home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / rmail / rmail.el.z / rmail.el
Encoding:
Text File  |  1998-05-21  |  83.1 KB  |  2,340 lines

  1. ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
  2.  
  3. ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994
  4. ;;; Free Software Foundation, Inc.
  5.  
  6. ;; Maintainer: FSF
  7. ;; Keywords: mail
  8.  
  9. ;; This file is part of XEmacs.
  10.  
  11. ;; XEmacs is free software; you can redistribute it and/or modify it
  12. ;; under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 2, or (at your option)
  14. ;; any later version.
  15.  
  16. ;; XEmacs is distributed in the hope that it will be useful, but
  17. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  19. ;; General Public License for more details.
  20.  
  21. ;; You should have received a copy of the GNU General Public License
  22. ;; along with XEmacs; see the file COPYING.  If not, write to the 
  23. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  24. ;; Boston, MA 02111-1307, USA.
  25.  
  26. ;;; Code:
  27.  
  28. ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
  29. ;;   New features include attribute and keyword support, message
  30. ;;   selection by dispatch table, summary by attributes and keywords,
  31. ;;   expunging by dispatch table, sticky options for file commands.
  32.  
  33. ;; Extended by Bob Weiner of Motorola
  34. ;;   New features include: rmail and rmail-summary buffers remain
  35. ;;   synchronized and key bindings basically operate the same way in both
  36. ;;   buffers, summary by topic or by regular expression, rmail-reply-prefix
  37. ;;   variable, and a bury rmail buffer (wipe) command.
  38. ;;
  39.  
  40. (require 'mail-utils)
  41.  
  42. ;; For Emacs V18 compatibility
  43. (and (not (fboundp 'user-original-login-name))
  44.      (fboundp 'user-real-login-name)
  45.      (defalias 'user-original-login-name 'user-real-login-name))
  46. (and (not (fboundp 'buffer-disable-undo))
  47.      (fboundp 'buffer-flush-undo)
  48.      (defalias 'buffer-disable-undo 'buffer-flush-undo))
  49.  
  50. ; These variables now declared in paths.el.
  51. ;(defvar rmail-spool-directory "/usr/spool/mail/"
  52. ;  "This is the name of the directory used by the system mailer for\n\
  53. ;delivering new mail.  It's name should end with a slash.")
  54. ;(defvar rmail-file-name
  55. ;  (expand-file-name "~/RMAIL")
  56. ;  "")
  57.  
  58. ;;;###autoload
  59. (defvar rmail-dont-reply-to-names nil "\
  60. *A regexp specifying names to prune of reply to messages.
  61. A value of nil means exclude your own name only.")
  62.  
  63. ;;;###autoload
  64. (defvar rmail-default-dont-reply-to-names "info-" "\
  65. A regular expression specifying part of the value of the default value of
  66. the variable `rmail-dont-reply-to-names', for when the user does not set
  67. `rmail-dont-reply-to-names' explicitly.  (The other part of the default
  68. value is the user's name.)
  69. It is useful to set this variable in the site customization file.")
  70.  
  71. ;;; XEmacs change: moved rmail-ignored-headers to sendmail.el for the
  72. ;;; benefit of automatically generated autoloads.
  73. ;;;minimalist FSF version
  74. ;(defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\
  75. ;*Gubbish headers one would rather not see.")
  76.  
  77. ;;;###autoload
  78. (defvar rmail-delete-after-output nil "\
  79. *Non-nil means automatically delete a message that is copied to a file.")
  80.  
  81. ;;;###autoload
  82. (defvar rmail-primary-inbox-list nil "\
  83. *List of files which are inboxes for user's primary mail file `~/RMAIL'.
  84. `nil' means the default, which is (\"/usr/spool/mail/$USER\")
  85. \(the name varies depending on the operating system,
  86. and the value of the environment variable MAIL overrides it).")
  87.  
  88. ;;;###autoload
  89. (defvar rmail-mail-new-frame nil
  90.   "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
  91.  
  92. ;;;###autoload
  93. (defvar rmail-retry-setup-hook nil
  94.   "Hook that `rmail-retry-failure' uses in place of `mail-setup-hook'.")
  95.  
  96. ;; These may be altered by site-init.el to match the format of mmdf files
  97. ;;  delimiting used on a given host (delim1 and delim2 from the config
  98. ;;  files).
  99.  
  100. (defvar mmdf-delim1 "^\001\001\001\001\n"
  101.   "Regexp marking the start of an mmdf message")
  102. (defvar mmdf-delim2 "^\001\001\001\001\n"
  103.   "Regexp marking the end of an mmdf message")
  104.  
  105. (defvar rmail-message-filter nil
  106.   "If non nil, is a filter function for new headers in RMAIL.
  107. Called with region narrowed to unformatted header.")
  108.  
  109. (defvar rmail-reply-prefix "Re: "
  110.   "String to prepend to Subject line when replying to a message.")
  111.  
  112. (defvar rmail-mode-map nil)
  113.  
  114. (defvar rmail-inbox-list nil)
  115. (defvar rmail-keywords nil)
  116.  
  117. ;; Message counters and markers.  Deleted flags.
  118.  
  119. (defvar rmail-current-message nil)
  120. (defvar rmail-total-messages nil)
  121. (defvar rmail-message-vector nil)
  122. (defvar rmail-deleted-vector nil)
  123.  
  124. ;; These are used by autoloaded rmail-summary.
  125.  
  126. (defvar rmail-summary-buffer nil)
  127. (defvar rmail-summary-vector nil)
  128.  
  129. ;; `Sticky' default variables.
  130.  
  131. ;; Last individual label specified to a or k.
  132. (defvar rmail-last-label nil)
  133. ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
  134. (defvar rmail-last-multi-labels nil)
  135. ;;;###autoload
  136. (defvar rmail-last-file nil)
  137. (defvar rmail-last-regexp nil)
  138. (defvar rmail-last-rmail-file (expand-file-name "~/XMAIL"))
  139.  
  140. ;;; Regexp matching the delimiter of messages in UNIX mail format
  141. ;;; (UNIX From lines), minus the initial ^.  Note that if you change
  142. ;;; this expression, you must change the code in rmail-nuke-pinhead-header
  143. ;;; that knows the exact ordering of the \\( \\) subexpressions.
  144. (defvar rmail-unix-mail-delimiter
  145.   (let ((time-zone-regexp
  146.      (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
  147.          "\\|[-+]?[0-9][0-9][0-9][0-9]"
  148.          "\\|"
  149.          "\\) *")))
  150.     (concat
  151.      "From "
  152.  
  153.      ;; Username, perhaps with a quoted section that can contain spaces.
  154.      "\\("
  155.      "[^ \n]*"
  156.      "\\(\\|\".*\"[^ \n]*\\)"
  157.      "\\)  ?"
  158.  
  159.      ;; The time the message was sent.
  160.      "\\([^ \n]*\\) *"            ; day of the week
  161.      "\\([^ ]*\\) *"            ; month
  162.      "\\([0-9]*\\) *"            ; day of month
  163.      "\\([0-9:]*\\) *"            ; time of day
  164.  
  165.      ;; Perhaps a time zone, specified by an abbreviation, or by a
  166.      ;; numeric offset.
  167.      time-zone-regexp
  168.  
  169.      ;; The year.
  170.      " [0-9][0-9]\\([0-9]*\\) *"
  171.  
  172.      ;; On some systems the time zone can appear after the year, too.
  173.      time-zone-regexp
  174.  
  175.      ;; I'm not sure what this is.
  176.      "\\(remote from [^\n]*\\)?"
  177.  
  178.      "\n"))
  179.   )
  180.  
  181. ;; Perform BODY in the summary buffer
  182. ;; in such a way that its cursor is properly updated in its own window.
  183. (defmacro rmail-select-summary (&rest body)
  184.   (` (progn (if (rmail-summary-displayed)
  185.         (let ((window (selected-window)))
  186.           (save-excursion
  187.             (unwind-protect
  188.             (progn
  189.               (pop-to-buffer rmail-summary-buffer)
  190.               (,@ body))
  191.               (select-window window))))
  192.           (save-excursion
  193.         (set-buffer rmail-summary-buffer)
  194.         (progn (,@ body))))
  195.         (rmail-maybe-display-summary))))
  196.  
  197.  
  198. ;;; 1996/12/9 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  199.  
  200. ;;; @ for mule and MIME
  201. ;;;
  202.  
  203. (require 'tm-view)
  204.  
  205. (defconst rmail-support-mime t)
  206. (defvar rmail-show-mime t)
  207. (defvar rmail-show-mime-method (function rmail-show-mime-message))
  208.  
  209. (defun rmail-show-all-header ()
  210.   (rmail-maybe-set-message-counters)
  211.   (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  212.   (let ((buffer-read-only nil))
  213.     (goto-char (point-min))
  214.     (forward-line 1)
  215.     (if (= (following-char) ?1)
  216.     (progn
  217.       (delete-char 1)
  218.       (insert ?0)
  219.       (forward-line 1)
  220.       (let ((case-fold-search t))
  221.         (while (looking-at "Summary-Line:\\|Mail-From:")
  222.           (forward-line 1)))
  223.       (insert "*** EOOH ***\n")
  224.       (forward-char -1)
  225.       (search-forward "\n*** EOOH ***\n")
  226.       (forward-line -1)
  227.       (let ((temp (point)))
  228.         (and (search-forward "\n\n" nil t)
  229.          (delete-region temp (point))))
  230.       (goto-char (point-min))
  231.       (search-forward "\n*** EOOH ***\n")
  232.       (narrow-to-region (point) (point-max)))
  233.       )))
  234.  
  235. (defun rmail-show-mime-message ()
  236.   (rmail-show-all-header)
  237.   (let ((abuf (current-buffer))
  238.     (buf-name (format "*Preview-%s [%d/%d]*"
  239.               (buffer-name)
  240.               rmail-current-message rmail-total-messages))
  241.     buf win)
  242.     (if (and mime::article/preview-buffer
  243.          (setq buf (get-buffer mime::article/preview-buffer))
  244.          )
  245.     (progn
  246.       (save-excursion
  247.         (set-buffer buf)
  248.         (rename-buffer buf-name)
  249.         )
  250.       (if (setq win (get-buffer-window buf))
  251.           (progn
  252.         (delete-window (get-buffer-window abuf))
  253.         (set-window-buffer win abuf)
  254.         (set-buffer abuf)
  255.         ))
  256.       ))
  257.     (setq win (get-buffer-window abuf))
  258.     (save-window-excursion
  259.       (mime/viewer-mode nil nil nil nil buf-name rmail-mode-map)
  260.       (or buf
  261.       (setq buf (current-buffer))
  262.       )
  263.       )
  264.     (set-window-buffer win buf)
  265.     ))
  266.  
  267. (set-alist 'mime-viewer/code-converter-alist
  268.        'rmail-mode
  269.        (function mime-charset/decode-buffer))
  270.  
  271. (set-alist 'mime-viewer/quitting-method-alist
  272.        'rmail-mode
  273.        (function rmail-quit)
  274.        )
  275.  
  276. (set-alist 'mime-viewer/over-to-previous-method-alist
  277.        'rmail-mode
  278.        (function
  279.         (lambda ()
  280.           (rmail-previous-undeleted-message 1)
  281.           )))
  282.  
  283. (set-alist 'mime-viewer/over-to-next-method-alist
  284.        'rmail-mode
  285.        (function
  286.         (lambda ()
  287.           (rmail-next-undeleted-message 1)
  288.           )))
  289.  
  290. (set-alist 'mime-viewer/show-summary-method
  291.        'rmail-mode
  292.        (function rmail-summary))
  293.  
  294.  
  295. ;;;; *** Rmail Mode ***
  296.  
  297. ;;;###autoload
  298. (defun rmail (&optional file-name-arg)
  299.   "Read and edit incoming mail.
  300. Moves messages into file named by `rmail-file-name' (a babyl format file)
  301.  and edits that file in RMAIL Mode.
  302. Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
  303.  
  304. May be called with filename as argument; then performs rmail editing on
  305. that file, but does not copy any new mail into the file."
  306.   (interactive (if current-prefix-arg
  307.            (list (read-file-name "Run rmail on RMAIL file: "
  308.                      nil nil t))))
  309.   (if (string-match "XEmacs" emacs-version)
  310.       (require 'rmail-xemacs))
  311.   (or rmail-last-file
  312.       (setq rmail-last-file (expand-file-name "~/xmail")))
  313.   (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
  314.      (existed (get-file-buffer file-name)))
  315.     ;; Like find-file, but in the case where a buffer existed
  316.     ;; and the file was reverted, recompute the message-data.
  317.     (if (and existed (not (verify-visited-file-modtime existed)))
  318.     (progn
  319.       ;; Don't be confused by apparent local-variables spec
  320.       ;; in the last message in the RMAIL file.
  321.       (let ((enable-local-variables nil))
  322.         (find-file file-name))
  323.       (if (and (verify-visited-file-modtime existed)
  324.            (eq major-mode 'rmail-mode))
  325.           (progn (rmail-forget-messages)
  326.              (rmail-set-message-counters))))
  327.       (let ((enable-local-variables nil))
  328.     (find-file file-name)))
  329.     (if (eq major-mode 'rmail-edit-mode)
  330.     (error "Exit Rmail Edit mode before getting new mail."))
  331.     (if (and existed (> (buffer-size) 0))
  332.     ;; Buffer not new and not empty; ensure in proper mode, but that's all.
  333.     (or (eq major-mode 'rmail-mode)
  334.         (rmail-mode-2))
  335.       (rmail-mode-2)
  336.       ;; Convert all or part to Babyl file if possible.
  337.       (rmail-convert-file)
  338.       (goto-char (point-max))
  339.       (if (null rmail-inbox-list)
  340.       (progn
  341.         (rmail-set-message-counters)
  342.         (rmail-show-message))))
  343.     (let ((existing-unseen (rmail-first-unseen-message)))
  344.       (or file-name-arg
  345.       (rmail-get-new-mail))
  346.       ;; Show the first unseen message, which might be from a previous session
  347.       ;; or might have been just read in by rmail-get-new-mail.  Must
  348.       ;; determine already unseen messages first, as rmail-get-new-mail
  349.       ;; positions on the first new message, thus marking it as seen.
  350.       (rmail-show-message existing-unseen))))
  351.  
  352. ;; Given the value of MAILPATH, return a list of inbox file names.
  353. ;; This is turned off because it is not clear that the user wants
  354. ;; all these inboxes to feed into the primary rmail file.
  355. ; (defun rmail-convert-mailpath (string)
  356. ;   (let (idx list)
  357. ;     (while (setq idx (string-match "[%:]" string))
  358. ;       (let ((this (substring string 0 idx)))
  359. ;     (setq string (substring string (1+ idx)))
  360. ;     (setq list (cons (if (string-match "%" this)
  361. ;                  (substring this 0 (string-match "%" this))
  362. ;                this)
  363. ;              list))))
  364. ;     list))
  365.  
  366. ;; Someone said:
  367. ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  368. ; will not cause emacs 18.55 problems.
  369. ;; To which jwz responds: maybe so but it's damned annoying so don't do it.
  370.  
  371. (defun rmail-convert-file ()
  372.   (let (convert)
  373.     (widen)
  374.     (goto-char (point-min))
  375.     ;; If file doesn't start like a Babyl file,
  376.     ;; convert it to one, by adding a header and converting each message.
  377.     (cond ((looking-at "BABYL OPTIONS:"))
  378.       ((looking-at "Version: 5\n")
  379.        ;; Losing babyl file made by old version of Rmail.
  380.        ;; Just fix the babyl file header; don't make a new one,
  381.        ;; so we don't lose the Labels: file attribute, etc.
  382.        (let ((buffer-read-only nil))
  383.          ;; NO NO NO
  384.          ;;(insert "BABYL OPTIONS: -*- rmail -*-\n")
  385.          (insert "BABYL OPTIONS:\n")))
  386.       ((equal (point-min) (point-max))
  387.        ;; Empty RMAIL file.  Just insert the header.
  388.        (rmail-insert-rmail-file-header))
  389.       (t
  390.        ;; Non-empty file in non-RMAIL format.  Add header and convert.
  391.        (setq convert t)
  392.        (rmail-insert-rmail-file-header)))
  393.     ;; If file was not a Babyl file or if there are
  394.     ;; Unix format messages added at the end,
  395.     ;; convert file as necessary.
  396.     (if (or convert
  397.         (save-excursion
  398.           (goto-char (point-max))
  399.           (search-backward "\^_")
  400.           (forward-char 1)
  401.           (looking-at "\n*From ")))
  402.     (let ((buffer-read-only nil))
  403.       (message "Converting to Babyl format...")
  404.       ;; If file needs conversion, convert it all,
  405.       ;; except for the BABYL header.
  406.       ;; (rmail-convert-to-babyl-format would delete the header.)
  407.       (goto-char (point-min))
  408.       (search-forward "\n\^_" nil t)
  409.       (narrow-to-region (point) (point-max))
  410.       (rmail-convert-to-babyl-format)
  411.       (message "Converting to Babyl format...done")))))
  412.  
  413. ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
  414. ;;; will not cause emacs 18.55 problems.
  415. ;;; (Whatever, see above. -jwz)
  416.  
  417. (defun rmail-insert-rmail-file-header ()
  418.   (let ((buffer-read-only nil))
  419.     ;; NO NO NO a thousand times NO
  420. ;;    (insert "BABYL OPTIONS: -*- rmail -*-
  421.     (insert "BABYL OPTIONS:
  422. Version: 5
  423. Labels:
  424. Note:   This is the header of an rmail file.
  425. Note:   If you are seeing it in rmail,
  426. Note:    it means the file has no messages in it.\n\^_")))
  427.  
  428. (if rmail-mode-map
  429.     nil
  430.   (setq rmail-mode-map (make-keymap))
  431.   (suppress-keymap rmail-mode-map)
  432.   (define-key rmail-mode-map "a"      'rmail-add-label)
  433.   (define-key rmail-mode-map "b"      'rmail-bury)
  434.   (define-key rmail-mode-map "c"      'rmail-continue)
  435.   (define-key rmail-mode-map "d"      'rmail-delete-forward)
  436.   (define-key rmail-mode-map "\C-d"   'rmail-delete-backward)
  437.   (define-key rmail-mode-map "e"      'rmail-edit-current-message)
  438.   (define-key rmail-mode-map "f"      'rmail-forward)
  439.   (define-key rmail-mode-map "g"      'rmail-get-new-mail)
  440.   (define-key rmail-mode-map "h"      'rmail-summary)
  441.   (define-key rmail-mode-map "i"      'rmail-input)
  442.   (define-key rmail-mode-map "j"      'rmail-show-message)
  443.   (define-key rmail-mode-map "k"      'rmail-kill-label)
  444.   (define-key rmail-mode-map "l"      'rmail-summary-by-labels)
  445.   (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
  446.   (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
  447.   (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
  448.   (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
  449.   (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
  450.   (define-key rmail-mode-map "m"      'rmail-mail)
  451.   (define-key rmail-mode-map "\em"    'rmail-retry-failure)
  452.   (define-key rmail-mode-map "n"      'rmail-next-undeleted-message)
  453.   (define-key rmail-mode-map "\en"    'rmail-next-message)
  454.   (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
  455.   (define-key rmail-mode-map "o"      'rmail-output-to-rmail-file)
  456.   (define-key rmail-mode-map "\C-o"   'rmail-output)
  457.   (define-key rmail-mode-map "p"      'rmail-previous-undeleted-message)
  458.   (define-key rmail-mode-map "\ep"    'rmail-previous-message)
  459.   (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
  460.   (define-key rmail-mode-map "q"      'rmail-quit)
  461.   (define-key rmail-mode-map "r"      'rmail-reply)
  462. ;; I find I can't live without the default M-r command -- rms.
  463. ;;  (define-key rmail-mode-map "\er"  'rmail-search-backwards)
  464.   (define-key rmail-mode-map "s"      'rmail-expunge-and-save)
  465.   (define-key rmail-mode-map "\es"    'rmail-search)
  466.   (define-key rmail-mode-map "t"      'rmail-toggle-header)
  467.   (define-key rmail-mode-map "u"      'rmail-undelete-previous-message)
  468.   (define-key rmail-mode-map "w"      'rmail-edit-current-message)
  469.   (define-key rmail-mode-map "x"      'rmail-expunge)
  470.   (define-key rmail-mode-map "."      'rmail-beginning-of-message)
  471.   (define-key rmail-mode-map "<"      'rmail-first-message)
  472.   (define-key rmail-mode-map ">"      'rmail-last-message)
  473.   (define-key rmail-mode-map " "      'scroll-up)
  474.   (define-key rmail-mode-map "\177"   'scroll-down)
  475.   (define-key rmail-mode-map "?"      'describe-mode)
  476.   (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
  477.   (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
  478.   (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
  479.   (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
  480.   (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
  481.   (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
  482.   )
  483.  
  484. ;(define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
  485. ;
  486. ;(define-key rmail-mode-map [menu-bar classify]
  487. ;  (cons "Classify" (make-sparse-keymap "Classify")))
  488. ;
  489. ;(define-key rmail-mode-map [menu-bar classify output-inbox]
  490. ;  '("Output (inbox)" . rmail-output))
  491. ;
  492. ;(define-key rmail-mode-map [menu-bar classify output]
  493. ;  '("Output (Rmail)" . rmail-output-to-rmail-file))
  494. ;
  495. ;(define-key rmail-mode-map [menu-bar classify kill-label]
  496. ;  '("Kill Label" . rmail-kill-label))
  497. ;
  498. ;(define-key rmail-mode-map [menu-bar classify add-label]
  499. ;  '("Add Label" . rmail-add-label))
  500. ;
  501. ;(define-key rmail-mode-map [menu-bar summary]
  502. ;  (cons "Summary" (make-sparse-keymap "Summary")))
  503. ;
  504. ;(define-key rmail-mode-map [menu-bar summary labels]
  505. ;  '("By Labels" . rmail-summary-by-labels))
  506. ;
  507. ;(define-key rmail-mode-map [menu-bar summary recipients]
  508. ;  '("By Recipients" . rmail-summary-by-recipients))
  509. ;
  510. ;(define-key rmail-mode-map [menu-bar summary topic]
  511. ;  '("By Topic" . rmail-summary-by-topic))
  512. ;
  513. ;(define-key rmail-mode-map [menu-bar summary regexp]
  514. ;  '("By Regexp" . rmail-summary-by-regexp))
  515. ;
  516. ;(define-key rmail-mode-map [menu-bar summary all]
  517. ;  '("All" . rmail-summary))
  518. ;
  519. ;(define-key rmail-mode-map [menu-bar mail]
  520. ;  (cons "Mail" (make-sparse-keymap "Mail")))
  521. ;
  522. ;(define-key rmail-mode-map [menu-bar mail continue]
  523. ;  '("Continue" . rmail-continue))
  524. ;
  525. ;(define-key rmail-mode-map [menu-bar mail forward]
  526. ;  '("Forward" . rmail-forward))
  527. ;
  528. ;(define-key rmail-mode-map [menu-bar mail retry]
  529. ;  '("Retry" . rmail-retry-failure))
  530. ;
  531. ;(define-key rmail-mode-map [menu-bar mail reply]
  532. ;  '("Reply" . rmail-reply))
  533. ;
  534. ;(define-key rmail-mode-map [menu-bar mail mail]
  535. ;  '("Mail" . rmail-mail))
  536. ;
  537. ;(define-key rmail-mode-map [menu-bar delete]
  538. ;  (cons "Delete" (make-sparse-keymap "Delete")))
  539. ;
  540. ;(define-key rmail-mode-map [menu-bar delete expunge/save]
  541. ;  '("Expunge/Save" . rmail-expunge-and-save))
  542. ;
  543. ;(define-key rmail-mode-map [menu-bar delete expunge]
  544. ;  '("Expunge" . rmail-expunge))
  545. ;
  546. ;(define-key rmail-mode-map [menu-bar delete undelete]
  547. ;  '("Undelete" . rmail-undelete-previous-message))
  548. ;
  549. ;(define-key rmail-mode-map [menu-bar delete delete]
  550. ;  '("Delete" . rmail-delete-forward))
  551. ;
  552. ;(define-key rmail-mode-map [menu-bar move]
  553. ;  (cons "Move" (make-sparse-keymap "Move")))
  554. ;
  555. ;(define-key rmail-mode-map [menu-bar move search-back]
  556. ;  '("Search Back" . rmail-search-backward))
  557. ;
  558. ;(define-key rmail-mode-map [menu-bar move search]
  559. ;  '("Search" . rmail-search))
  560. ;
  561. ;(define-key rmail-mode-map [menu-bar move previous]
  562. ;  '("Previous Nondeleted" . rmail-previous-undeleted-message))
  563. ;
  564. ;(define-key rmail-mode-map [menu-bar move next]
  565. ;  '("Next Nondeleted" . rmail-next-undeleted-message))
  566. ;
  567. ;(define-key rmail-mode-map [menu-bar move last]
  568. ;  '("Last" . rmail-last-message))
  569. ;
  570. ;(define-key rmail-mode-map [menu-bar move first]
  571. ;  '("First" . rmail-first-message))
  572. ;
  573. ;(define-key rmail-mode-map [menu-bar move previous]
  574. ;  '("Previous" . rmail-previous-message))
  575. ;
  576. ;(define-key rmail-mode-map [menu-bar move next]
  577. ;  '("Next" . rmail-next-message))
  578.  
  579. ;; Rmail mode is suitable only for specially formatted data.
  580. (put 'rmail-mode 'mode-class 'special)
  581.  
  582. ;;;###autoload
  583. (defun rmail-mode ()
  584.   "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
  585. All normal editing commands are turned off.
  586. Instead, these commands are available:
  587.  
  588. \\[rmail-beginning-of-message]    Move point to front of this message (same as \\[beginning-of-buffer]).
  589. \\[scroll-up]    Scroll to next screen of this message.
  590. \\[scroll-down]    Scroll to previous screen of this message.
  591. \\[rmail-next-undeleted-message]    Move to Next non-deleted message.
  592. \\[rmail-previous-undeleted-message]    Move to Previous non-deleted message.
  593. \\[rmail-next-message]    Move to Next message whether deleted or not.
  594. \\[rmail-previous-message]    Move to Previous message whether deleted or not.
  595. \\[rmail-first-message]    Move to the first message in Rmail file.
  596. \\[rmail-last-message]    Move to the last message in Rmail file.
  597. \\[rmail-show-message]    Jump to message specified by numeric position in file.
  598. \\[rmail-search]    Search for string and show message it is found in.
  599. \\[rmail-delete-forward]    Delete this message, move to next nondeleted.
  600. \\[rmail-delete-backward]    Delete this message, move to previous nondeleted.
  601. \\[rmail-undelete-previous-message]    Undelete message.  Tries current message, then earlier messages
  602.     till a deleted message is found.
  603. \\[rmail-edit-current-message]    Edit the current message.  \\[rmail-cease-edit] to return to Rmail.
  604. \\[rmail-expunge]    Expunge deleted messages.
  605. \\[rmail-expunge-and-save]    Expunge and save the file.
  606. \\[rmail-quit]       Quit Rmail: expunge, save, then switch to another buffer.
  607. \\[save-buffer] Save without expunging.
  608. \\[rmail-get-new-mail]    Move new mail from system spool directory into this file.
  609. \\[rmail-mail]    Mail a message (same as \\[mail-other-window]).
  610. \\[rmail-continue]    Continue composing outgoing message started before.
  611. \\[rmail-reply]    Reply to this message.  Like \\[rmail-mail] but initializes some fields.
  612. \\[rmail-retry-failure]    Send this message again.  Used on a mailer failure message.
  613. \\[rmail-forward]    Forward this message to another user.
  614. \\[rmail-output-to-rmail-file]       Output this message to an Rmail file (append it).
  615. \\[rmail-output]    Output this message to a Unix-format mail file (append it).
  616. \\[rmail-input]    Input Rmail file.  Run Rmail on that file.
  617. \\[rmail-add-label]    Add label to message.  It will be displayed in the mode line.
  618. \\[rmail-kill-label]    Kill label.  Remove a label from current message.
  619. \\[rmail-next-labeled-message]   Move to Next message with specified label
  620.           (label defaults to last one specified).
  621.           Standard labels: filed, unseen, answered, forwarded, deleted.
  622.           Any other label is present only if you add it with \\[rmail-add-label].
  623. \\[rmail-previous-labeled-message]   Move to Previous message with specified label
  624. \\[rmail-summary]    Show headers buffer, with a one line summary of each message.
  625. \\[rmail-summary-by-labels]    Summarize only messages with particular label(s).
  626. \\[rmail-summary-by-recipients]   Summarize only messages with particular recipient(s).
  627. \\[rmail-summary-by-regexp]   Summarize only messages with particular regexp(s).
  628. \\[rmail-summary-by-topic]   Summarize only messages with subject line regexp(s).
  629. \\[rmail-toggle-header]    Toggle display of complete header."
  630.   (interactive)
  631.   (rmail-mode-2)
  632.   (rmail-set-message-counters)
  633.   (rmail-show-message rmail-total-messages))
  634.  
  635. (defun rmail-mode-2 ()
  636.   (kill-all-local-variables)
  637.   (rmail-mode-1)
  638.   (rmail-variables)
  639.   (run-hooks 'rmail-mode-hook))
  640.  
  641. (defun rmail-mode-1 ()
  642.   (setq major-mode 'rmail-mode)
  643.   (setq mode-name "RMAIL")
  644.   (setq buffer-read-only t)
  645.   ;; No need to auto save RMAIL files.
  646.   ;; says who??? (asks jwz)
  647. ;;  (setq buffer-auto-save-file-name nil)
  648.   (if (boundp 'mode-line-modified)
  649.       (setq mode-line-modified "--- ")
  650.     (setq mode-line-format
  651.       (cons "--- " (cdr (default-value 'mode-line-format)))))
  652.   (use-local-map rmail-mode-map)
  653.   (set-syntax-table text-mode-syntax-table)
  654.   (setq local-abbrev-table text-mode-abbrev-table))
  655.  
  656. (defun rmail-variables ()
  657.   (make-local-variable 'revert-buffer-function)
  658.   (setq revert-buffer-function 'rmail-revert)
  659.   (make-local-variable 'rmail-last-label)
  660.   (make-local-variable 'rmail-last-regexp)
  661.   (make-local-variable 'rmail-deleted-vector)
  662.   (make-local-variable 'rmail-summary-buffer)
  663.   (make-local-variable 'rmail-summary-vector)
  664.   (make-local-variable 'rmail-current-message)
  665.   (make-local-variable 'rmail-total-messages)
  666.   (make-local-variable 'require-final-newline)
  667.   (setq require-final-newline nil)
  668.   (make-local-variable 'version-control)
  669.   (setq version-control 'never)
  670.   (make-local-variable 'file-precious-flag)
  671.   (setq file-precious-flag t)
  672.   (make-local-variable 'rmail-message-vector)
  673.   (make-local-variable 'rmail-last-file)
  674.   (make-local-variable 'rmail-inbox-list)
  675.   (setq rmail-inbox-list (rmail-parse-file-inboxes))
  676.   ;; Provide default set of inboxes for primary mail file ~/RMAIL.
  677.   (and (null rmail-inbox-list)
  678.        (or (equal buffer-file-name (expand-file-name rmail-file-name))
  679.        (equal buffer-file-truename
  680.           (abbreviate-file-name (file-truename rmail-file-name))))
  681.        (setq rmail-inbox-list
  682.          (or rmail-primary-inbox-list
  683.          ;; XEmacs change: FSF had removed "~/mbox" from this list, 
  684.          ;; but users expect that to work and don't understand why
  685.          ;; it changed.
  686.          (list "~/mbox"
  687.                (or (getenv "MAIL")
  688.                (concat rmail-spool-directory
  689.                    (user-original-login-name)))))))
  690.   (make-local-variable 'rmail-keywords)
  691.   ;; this gets generated as needed
  692.   (setq rmail-keywords nil))
  693.  
  694. ;; Handle M-x revert-buffer done in an rmail-mode buffer.
  695. (defun rmail-revert (arg noconfirm)
  696.   (let (revert-buffer-function)
  697.     ;; Call our caller again, but this time it does the default thing.
  698.     (if (revert-buffer arg noconfirm)
  699.     ;; If the user said "yes", and we changed something,
  700.     ;; reparse the messages.
  701.     (progn
  702.       (rmail-convert-file)
  703.       (goto-char (point-max))
  704.       (rmail-set-message-counters)
  705.       (rmail-show-message)))))
  706.  
  707. ;; Return a list of files from this buffer's Mail: option.
  708. ;; Does not assume that messages have been parsed.
  709. ;; Just returns nil if buffer does not look like Babyl format.
  710. (defun rmail-parse-file-inboxes ()
  711.   (save-excursion
  712.     (save-restriction
  713.       (widen)
  714.       (goto-char 1)
  715.       (cond ((looking-at "BABYL OPTIONS:")
  716.          (search-forward "\n\^_" nil 'move)
  717.          (narrow-to-region 1 (point))
  718.          (goto-char 1)
  719.          (if (search-forward "\nMail:" nil t)
  720.          (progn
  721.            (narrow-to-region (point) (progn (end-of-line) (point)))
  722.            (goto-char (point-min))
  723.            (mail-parse-comma-list))))))))
  724.  
  725. (defun rmail-expunge-and-save ()
  726.   "Expunge and save RMAIL file."
  727.   (interactive)
  728.   (rmail-expunge)
  729.   (save-buffer))
  730.  
  731. (defun rmail-quit ()
  732.   "Quit out of RMAIL."
  733.   (interactive)
  734.   (if (eq major-mode 'mime/viewer-mode)
  735.       (let ((buf mime::preview/article-buffer)
  736.         (pbuf (current-buffer))
  737.         )
  738.     (switch-to-buffer buf)
  739.     (bury-buffer pbuf)
  740.     ))
  741.   (let (rmail-show-mime)
  742.     (rmail-expunge-and-save)
  743.     )
  744.   ;; Don't switch to the summary buffer even if it was recently visible.
  745.   (if (rmail-summary-exists)
  746.       (bury-buffer rmail-summary-buffer))
  747.   (let ((obuf (current-buffer)))
  748.     (switch-to-buffer (other-buffer))
  749.     (bury-buffer obuf)))
  750.  
  751. ;;;###autoload
  752. (defun rmail-input (filename)
  753.   "Run Rmail on file FILENAME."
  754.   (interactive "FRun rmail on RMAIL file: ")
  755.   (rmail filename))
  756.  
  757.  
  758. ;;;; *** Rmail input ***
  759.  
  760. ;; RLK feature not added in this version:
  761. ;; argument specifies inbox file or files in various ways.
  762.  
  763. (defun rmail-get-new-mail (&optional file-name)
  764.   "Move any new mail from this RMAIL file's inbox files.
  765. The inbox files can be specified with the file's Mail: option.  The
  766. variable `rmail-primary-inbox-list' specifies the inboxes for your
  767. primary RMAIL file if it has no Mail: option.  By default, this is
  768. your /usr/spool/mail/$USER.
  769.  
  770. You can also specify the file to get new mail from.  In this case, the
  771. file of new mail is not changed or deleted.  Noninteractively, you can
  772. pass the inbox file name as an argument.  Interactively, a prefix
  773. argument causes us to read a file name and use that file as the inbox."
  774.   (interactive
  775.    (list (if current-prefix-arg
  776.          (read-file-name "Get new mail from file: "))))
  777.   (or (verify-visited-file-modtime (current-buffer))
  778.       (progn
  779.     (find-file (buffer-file-name))
  780.     (setq buffer-read-only t)
  781.     (if (verify-visited-file-modtime (current-buffer))
  782.         (rmail-forget-messages))))
  783.   (rmail-maybe-set-message-counters)
  784.   (widen)
  785.   ;; Get rid of all undo records for this buffer.
  786.   (or (eq buffer-undo-list t)
  787.       (setq buffer-undo-list nil))
  788.   (unwind-protect
  789.       (let ((opoint (point))
  790.         (new-messages 0)
  791.         (delete-files ())
  792.         ;; If buffer has not changed yet, and has not been saved yet,
  793.         ;; don't replace the old backup file now.
  794.         (make-backup-files (and make-backup-files (buffer-modified-p)))
  795.         (buffer-read-only nil)
  796.         ;; Don't make undo records for what we do in getting mail.
  797.         (buffer-undo-list t))
  798.     (goto-char (point-max))
  799.     (skip-chars-backward " \t\n")        ; just in case of brain damage
  800.     (delete-region (point) (point-max)) ; caused by require-final-newline
  801.     (save-excursion
  802.       (save-restriction
  803.         (narrow-to-region (point) (point))
  804.         ;; Read in the contents of the inbox files,
  805.         ;; renaming them as necessary,
  806.         ;; and adding to the list of files to delete eventually.
  807.         (if file-name
  808.         (rmail-insert-inbox-text (list file-name) nil)
  809.           (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
  810.         ;; Scan the new text and convert each message to babyl format.
  811.         (goto-char (point-min))
  812.         (save-excursion
  813.           (setq new-messages (rmail-convert-to-babyl-format)))
  814.         (or (zerop new-messages)
  815.         (progn ;;let (success)
  816.           (widen)
  817.           (search-backward "\n\^_")
  818.           (narrow-to-region (point) (point-max))
  819.           (goto-char (1+ (point-min)))
  820.           (rmail-count-new-messages)
  821.           (save-buffer)))
  822.         ;; Delete the old files, now that babyl file is saved.
  823.         (while delete-files
  824.           (condition-case ()
  825.           ;; First, try deleting.
  826.           (condition-case ()
  827.               (delete-file (car delete-files))
  828.             (file-error
  829.              ;; If we can't delete it, truncate it.
  830.              (write-region (point) (point) (car delete-files))))
  831.         (file-error nil))
  832.           (setq delete-files (cdr delete-files)))))
  833.     (if (= new-messages 0)
  834.         (progn (goto-char opoint)
  835.            (if (or file-name rmail-inbox-list)
  836.                (message "(No new mail has arrived)")))
  837.       (if (rmail-summary-exists)
  838.           (rmail-select-summary
  839.         (rmail-update-summary)))
  840.       (message "%d new message%s read"
  841.            new-messages (if (= 1 new-messages) "" "s"))
  842.       ;; #### BOGUS!  Run a hook here instead and let time.el do it.
  843.       (and (boundp 'display-time-string)
  844.            display-time-string
  845.            (stringp display-time-string)
  846.            (string-match " Mail" display-time-string)
  847.            (setq display-time-string
  848.              (concat
  849.               (substring display-time-string 0 (match-beginning 0))
  850.               (substring display-time-string (match-end 0))))
  851.            (force-mode-line-update 'all))))
  852.     ;; Don't leave the buffer screwed up if we get a disk-full error.
  853.     (rmail-show-message)))
  854.  
  855. (defun rmail-insert-inbox-text (files renamep)
  856.   (let (file tofile delete-files movemail popmail)
  857.     (while files
  858.       (setq file (expand-file-name (substitute-in-file-name (car files)))
  859.         ;;>> un*x specific <<
  860.         ;; The "+" used to be "~", which is an extremely poor choice;
  861.         ;; it might accidentally be deleted when space is low
  862.         ;; (as happened to me!).
  863.         tofile (concat file "+"))
  864.       ;; If getting from mail spool directory,
  865.       ;; use movemail to move rather than just renaming,
  866.       ;; so as to interlock with the mailer.
  867.       (setq movemail (equal (file-name-directory file) rmail-spool-directory)
  868.         popmail (string-match "^po:" (file-name-nondirectory file)))
  869.       (if popmail (setq file (file-name-nondirectory file)
  870.             renamep t))
  871.       (if movemail
  872.       (progn
  873.         (setq tofile (expand-file-name
  874.                ;; Generate name to move to from inbox name,
  875.                ;; in case of multiple inboxes that need moving.
  876.                (concat ".newmail-" (file-name-nondirectory file))
  877.                ;; Use the directory of this rmail file
  878.                ;; because it's a nuisance to use the homedir
  879.                ;; if that is on a full disk and this rmail
  880.                ;; file isn't.
  881.                (file-name-directory
  882.                  (expand-file-name buffer-file-name))))
  883.         ;; On some systems, /usr/spool/mail/foo is a directory
  884.         ;; and the actual inbox is /usr/spool/mail/foo/foo.
  885.         (if (file-directory-p file)
  886.         (setq file (expand-file-name (user-original-login-name)
  887.                          file)))))
  888.       (if popmail
  889.       (message "Getting mail from post office ...")
  890.     (if (or (and (file-exists-p tofile)
  891.              (/= 0 (nth 7 (file-attributes tofile))))
  892.         (and (file-exists-p file)
  893.              (/= 0 (nth 7 (file-attributes file)))))
  894.         (message "Getting mail from %s..." file)))
  895.       ;; Set TOFILE if have not already done so, and
  896.       ;; rename or copy the file FILE to TOFILE if and as appropriate.
  897.       (cond ((not renamep)
  898.          (setq tofile file))
  899.         ((or (file-exists-p tofile) (and (not popmail)
  900.                          (not (file-exists-p file))))
  901.          nil)
  902.         ((and (not movemail) (not popmail))
  903.          ;; Try copying.  If that fails (perhaps no space),
  904.          ;; rename instead.
  905.          (condition-case nil
  906.          (copy-file file tofile nil)
  907.            (error
  908.         (rename-file file tofile nil)))
  909.          ;; Make the real inbox file empty.
  910.          ;; Leaving it deleted could cause lossage
  911.          ;; because mailers often won't create the file.
  912.          (condition-case ()
  913.          (write-region (point) (point) file)
  914.            (file-error nil)))
  915.         (t
  916.          (let ((errors nil))
  917.            (unwind-protect
  918.            (save-excursion
  919.              (setq errors (generate-new-buffer " *rmail loss*"))
  920.              (buffer-disable-undo errors)
  921.              (call-process
  922.                (expand-file-name "movemail" exec-directory)
  923.                nil errors nil file tofile)
  924.              (if (not (buffer-modified-p errors))
  925.              ;; No output => movemail won
  926.              nil
  927.                (set-buffer errors)
  928.                (subst-char-in-region (point-min) (point-max)
  929.                          ?\n ?\  )
  930.                (goto-char (point-max))
  931.                (skip-chars-backward " \t")
  932.                (delete-region (point) (point-max))
  933.                (goto-char (point-min))
  934.                (if (looking-at "movemail: ")
  935.                (delete-region (point-min) (match-end 0)))
  936.                (beep t)
  937.                (message (concat "movemail: "
  938.                     (buffer-substring (point-min)
  939.                               (point-max))))
  940.                (sit-for 3)
  941.                nil))
  942.          (if errors (kill-buffer errors))))))
  943.       ;; At this point, TOFILE contains the name to read:
  944.       ;; Either the alternate name (if we renamed)
  945.       ;; or the actual inbox (if not renaming).
  946.       (if (file-exists-p tofile)
  947.       (let (size)
  948.         (goto-char (point-max))
  949.         (if (not (featurep 'mule))
  950.         (setq size (nth 1 (insert-file-contents tofile)))
  951.           ;; At first, read the file without converting coding-system.
  952.           (setq size (nth 1 (let ((coding-system-for-read 'no-conversion))
  953.                   (insert-file-contents tofile))))
  954.           ;; 1996/12/9 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  955.           ;;    Don't code-convert for RMAIL file
  956.           ;; Then, convert the contents if necessary.
  957.               ;; (if (> size 0)
  958.               ;;     (cond
  959.               ;;      ((looking-at "^From ")
  960.               ;;       ;; New mails.  Since the contents may be a mixture
  961.               ;;       ;; of various coding-systems, we must decode one
  962.               ;;       ;; mail by one.
  963.               ;;       (while (null (eobp))
  964.               ;;         (let ((from (point)))
  965.               ;;           (re-search-forward "^From " nil 'mv)
  966.               ;;           (rmail-decode-coding-system from (point)))))
  967.               ;;      ((looking-at "BABYL OPTIONS:\\|\^L")
  968.               ;;       ;; Babyl format, i.e. not a new mail.  We had better
  969.               ;;       ;; not to convert large region at once.
  970.               ;;       (while (null (eobp))
  971.               ;;         (let ((max-size (* 1024 1024))
  972.               ;;               (from (point)))
  973.               ;;           (goto-char (+ from max-size))
  974.               ;;           (re-search-forward "\^_" nil 'mv)
  975.               ;;           (rmail-decode-coding-system from (point)))))
  976.               ;;      (t
  977.               ;;       ;; Perhaps, MMDF format.  Since I don't know how to
  978.               ;;       ;; deal with it, convert all data at once.
  979.               ;;       (rmail-decode-coding-system (point) (point-max)))))
  980.           )
  981.         (goto-char (point-max))
  982.         (or (= (preceding-char) ?\n)
  983.         (zerop size)
  984.         (insert ?\n))
  985.         (setq delete-files (cons tofile delete-files))))
  986.       (message "")
  987.       (setq files (cdr files)))
  988.     delete-files))
  989.  
  990. ;; (if (not (featurep 'mule)) nil
  991. ;; 
  992. ;; (defvar mail-coding-system '*junet*)
  993. ;; 
  994. ;; (defun rmail-decode-coding-system (from to)
  995. ;;   (let (coding-system)
  996. ;;     ;; At first, detect the coding-system of the region and set it to
  997. ;;     ;; `coding-system'.
  998. ;;     (let ((detected-coding-system (code-detect-region from to))
  999. ;;           (coding (get-code mail-coding-system)))
  1000. ;;       (if (listp detected-coding-system)
  1001. ;;           ;; Something other than ASCII was found.  If a coding-system
  1002. ;;           ;; of which information is same as `mail-coding-system' is
  1003. ;;           ;; in the list of detected coding-systems, use it, else use
  1004. ;;           ;; the coding-system of the highest priority in the list.
  1005. ;;           (let ((l detected-coding-system))
  1006. ;;             (while (and l
  1007. ;;                         (null (eq (get-code (car l)) coding)))
  1008. ;;               (setq l (cdr l)))
  1009. ;;             (setq coding-system (car (or l detected-coding-system))))))
  1010. ;;     ;; Then, decode the region.
  1011. ;;     (if coding-system
  1012. ;;         (save-restriction
  1013. ;;           (narrow-to-region from to)
  1014. ;;           (code-convert from to coding-system '*internal*)
  1015. ;;           (goto-char (point-max))))))
  1016. ;; 
  1017. ;; ) ; (featurep 'mule)
  1018.  
  1019. ;; the  rmail-break-forwarded-messages  feature is not implemented
  1020. (defun rmail-convert-to-babyl-format ()
  1021.   (let ((count 0) start
  1022.     (case-fold-search nil)
  1023.     (invalid-input-resync
  1024.      (function (lambda ()
  1025.              (message "Invalid Babyl format in inbox!")
  1026.              (sit-for 1)
  1027.              ;; Try to get back in sync with a real message.
  1028.              (if (re-search-forward
  1029.               (concat mmdf-delim1 "\\|^From") nil t)
  1030.              (beginning-of-line)
  1031.                (goto-char (point-max)))))))
  1032.     (goto-char (point-min))
  1033.     (save-restriction
  1034.       (while (not (eobp))
  1035.     (cond ((looking-at "BABYL OPTIONS:");Babyl header
  1036.            (if (search-forward "\n\^_" nil t)
  1037.            ;; If we find the proper terminator, delete through there.
  1038.            (delete-region (point-min) (point))
  1039.          (funcall invalid-input-resync)
  1040.          (delete-region (point-min) (point))))
  1041.           ;; Babyl format message
  1042.           ((looking-at "\^L")
  1043.            (or (search-forward "\n\^_" nil t)
  1044.            (funcall invalid-input-resync))
  1045.            (setq count (1+ count))
  1046.            ;; Make sure there is no extra white space after the ^_
  1047.            ;; at the end of the message.
  1048.            ;; Narrowing will make sure that whatever follows the junk
  1049.            ;; will be treated properly.
  1050.            (delete-region (point)
  1051.                   (save-excursion
  1052.                 (skip-chars-forward " \t\n")
  1053.                 (point)))
  1054.            (narrow-to-region (point) (point-max)))
  1055.           ;;*** MMDF format
  1056.           ((let ((case-fold-search t))
  1057.          (looking-at mmdf-delim1))
  1058.            (let ((case-fold-search t))
  1059.          (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
  1060.          (setq start (point))
  1061.          (re-search-forward mmdf-delim2 nil t)
  1062.          (replace-match "\^_"))
  1063.            (save-excursion
  1064.          (save-restriction
  1065.            (narrow-to-region start (1- (point)))
  1066.            (goto-char (point-min))
  1067.            (while (search-forward "\n\^_" nil t); single char "\^_"
  1068.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  1069.            (narrow-to-region (point) (point-max))
  1070.            (setq count (1+ count)))
  1071.           ;;*** Mail format
  1072.           ((looking-at "^From ")
  1073.            (setq start (point))
  1074.            (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
  1075.            (rmail-nuke-pinhead-header)
  1076.            ;; If this message has a Content-Length field,
  1077.            ;; skip to the end of the contents.
  1078.            (let* ((header-end (save-excursion
  1079.                     (and (re-search-forward "\n\n" nil t)
  1080.                      (point))))
  1081.               (case-fold-search t)
  1082.               (size
  1083.                ;; Get the numeric value from the Content-Length field.
  1084.                (save-excursion
  1085.              ;; Back up to end of prev line,
  1086.              ;; in case the Content-Length field comes first.
  1087.              (forward-char -1)
  1088.              (and (search-forward "\ncontent-length: "
  1089.                           header-end t)
  1090.                   (let ((beg (point))
  1091.                     (eol (progn (end-of-line) (point))))
  1092.                 (read (buffer-substring beg eol)))))))
  1093.          (and size (numberp size) (>= size 0)
  1094.               (goto-char (+ header-end size))))
  1095.  
  1096.            (if (re-search-forward
  1097.             (concat "^[\^_]?\\("
  1098.                 rmail-unix-mail-delimiter
  1099.                 "\\|"
  1100.                 mmdf-delim1 "\\|"
  1101.                 "^BABYL OPTIONS:\\|"
  1102.                 "\^L\n[01],\\)") nil t)
  1103.            (goto-char (match-beginning 1))
  1104.          (goto-char (point-max)))
  1105.            (setq count (1+ count))
  1106.            (save-excursion
  1107.          (save-restriction
  1108.            (narrow-to-region start (point))
  1109.            (goto-char (point-min))
  1110.            (while (search-forward "\n\^_" nil t); single char
  1111.              (replace-match "\n^_")))); 2 chars: "^" and "_"
  1112.            (insert ?\^_)
  1113.            (narrow-to-region (point) (point-max)))
  1114.           ;;
  1115.           ;; This kludge is because some versions of sendmail.el
  1116.           ;; insert an extra newline at the beginning that shouldn't
  1117.           ;; be there.  sendmail.el has been fixed, but old versions
  1118.           ;; may still be in use.  -- rms, 7 May 1993.
  1119.           ((eolp) (delete-char 1))
  1120.           (t (error "Cannot convert to babyl format")))))
  1121.     count))
  1122.  
  1123. ;; Delete the "From ..." line, creating various other headers with
  1124. ;; information from it if they don't already exist.  Now puts the
  1125. ;; original line into a mail-from: header line for debugging and for
  1126. ;; use by the rmail-output function.
  1127. (defun rmail-nuke-pinhead-header ()
  1128.   (save-excursion
  1129.     (save-restriction
  1130.       (let ((start (point))
  1131.           (end (progn
  1132.            (condition-case ()
  1133.                (search-forward "\n\n")
  1134.              (error
  1135.               (goto-char (point-max))
  1136.               (insert "\n\n")))
  1137.            (point)))
  1138.         has-from has-date)
  1139.     (narrow-to-region start end)
  1140.     (let ((case-fold-search t))
  1141.       (goto-char start)
  1142.       (setq has-from (search-forward "\nFrom:" nil t))
  1143.       (goto-char start)
  1144.       (setq has-date (and (search-forward "\nDate:" nil t) (point)))
  1145.       (goto-char start))
  1146.     (let ((case-fold-search nil))
  1147.       (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
  1148.           (replace-match
  1149.         (concat
  1150.           "Mail-from: \\&"
  1151.           ;; Keep and reformat the date if we don't
  1152.           ;;  have a Date: field.
  1153.           (if has-date
  1154.               ""
  1155.             (concat
  1156.              "Date: \\3, \\5 \\4 \\9 \\6 "
  1157.             
  1158.              ;; The timezone could be matched by group 7 or group 10.
  1159.              ;; If neither of them matched, assume EST, since only
  1160.              ;; Easterners would be so sloppy.
  1161.              ;; It's a shame the substitution can't use "\\10".
  1162.              (cond
  1163.               ((/= (match-beginning 7) (match-end 7)) "\\7")
  1164.               ((/= (match-beginning 10) (match-end 10))
  1165.                (buffer-substring (match-beginning 10)
  1166.                      (match-end 10)))
  1167.               (t "EST"))
  1168.              "\n"))
  1169.           ;; Keep and reformat the sender if we don't
  1170.           ;; have a From: field.
  1171.           (if has-from
  1172.               ""
  1173.             "From: \\1\n"))
  1174.         t)))))))
  1175.  
  1176. ;;;; *** Rmail Message Formatting and Header Manipulation ***
  1177.  
  1178. (defun rmail-reformat-message (beg end)
  1179.   (goto-char beg)
  1180.   (forward-line 1)
  1181.   (if (/= (following-char) ?0)
  1182.       (error "Bad format in RMAIL file."))
  1183.   (let ((buffer-read-only nil)
  1184.     (delta (- (buffer-size) end)))
  1185.     (delete-char 1)
  1186.     (insert ?1)
  1187.     (forward-line 1)
  1188.     (let ((case-fold-search t))
  1189.       (while (looking-at "Summary-line:\\|Mail-From:")
  1190.      (forward-line 1)))
  1191.     (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
  1192.     (delete-region (point)
  1193.                (progn (forward-line 1) (point))))
  1194.     (let ((str (buffer-substring (point)
  1195.                  (save-excursion (search-forward "\n\n" end 'move)
  1196.                          (point)))))
  1197.       (insert str "*** EOOH ***\n")
  1198.       (narrow-to-region (point) (- (buffer-size) delta)))
  1199.     (goto-char (point-min))
  1200.     (if rmail-ignored-headers (rmail-clear-headers))
  1201.     (if rmail-message-filter (funcall rmail-message-filter))))
  1202.  
  1203. (defun rmail-clear-headers ()
  1204.   (if (search-forward "\n\n" nil t)
  1205.       (save-restriction
  1206.         (narrow-to-region (point-min) (point))
  1207.     (let ((buffer-read-only nil))
  1208.       (while (let ((case-fold-search t))
  1209.            (goto-char (point-min))
  1210.            (re-search-forward rmail-ignored-headers nil t))
  1211.         (beginning-of-line)
  1212.         (delete-region (point)
  1213.                (progn (re-search-forward "\n[^ \t]")
  1214.                   (forward-char -1)
  1215.                   (point))))))))
  1216.  
  1217. (defun rmail-toggle-header ()
  1218.   "Show original message header if pruned header currently shown, or vice versa."
  1219.   (interactive)
  1220.   (rmail-maybe-set-message-counters)
  1221.   (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
  1222.   (let ((buffer-read-only nil))
  1223.     (goto-char (point-min))
  1224.     (forward-line 1)
  1225.     (if (= (following-char) ?1)
  1226.     (progn (delete-char 1)
  1227.            (insert ?0)
  1228.            (forward-line 1)
  1229.            (let ((case-fold-search t))
  1230.           (while (looking-at "Summary-Line:\\|Mail-From:")
  1231.             (forward-line 1)))
  1232.            (insert "*** EOOH ***\n")
  1233.            (forward-char -1)
  1234.            (search-forward "\n*** EOOH ***\n")
  1235.            (forward-line -1)
  1236.            (let ((temp (point)))
  1237.          (and (search-forward "\n\n" nil t)
  1238.               (delete-region temp (point))))
  1239.            (goto-char (point-min))
  1240.            (search-forward "\n*** EOOH ***\n")
  1241.            (narrow-to-region (point) (point-max)))
  1242.       (rmail-reformat-message (point-min) (point-max)))))
  1243.  
  1244. ;;;; *** Rmail Attributes and Keywords ***
  1245.  
  1246. ;; Make a string describing current message's attributes and keywords
  1247. ;; and set it up as the name of a minor mode
  1248. ;; so it will appear in the mode line.
  1249. (defun rmail-display-labels ()
  1250.   (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
  1251.     (save-excursion
  1252.       (unwind-protect
  1253.       (progn
  1254.         (widen)
  1255.         (goto-char (rmail-msgbeg rmail-current-message))
  1256.         (forward-line 1)
  1257.         (if (looking-at "[01],")
  1258.         (progn
  1259.           (narrow-to-region (point) (progn (end-of-line) (point)))
  1260.           ;; Truly valid BABYL format requires a space before each
  1261.           ;; attribute or keyword name.  Put them in if missing.
  1262.           (let (buffer-read-only)
  1263.             (goto-char (point-min))
  1264.             (while (search-forward "," nil t)
  1265.               (or (looking-at "[ ,]") (eobp)
  1266.               (insert " "))))
  1267.           (goto-char (point-max))
  1268.           (if (search-backward ",," nil 'move)
  1269.               (progn
  1270.             (if (> (point) (1+ (point-min)))
  1271.                 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
  1272.             (if (> (- (point-max) (point)) 2)
  1273.                 (setq blurb
  1274.                   (concat blurb
  1275.                       ";"
  1276.                       (buffer-substring (+ (point) 3)
  1277.                                 (1- (point-max)))))))))))
  1278.     ;; Note: we don't use save-restriction because that does not work right
  1279.     ;; if changes are made outside the saved restriction
  1280.     ;; before that restriction is restored.
  1281.     (narrow-to-region beg end)
  1282.     (set-marker beg nil)
  1283.     (set-marker end nil)))
  1284.     (while (string-match " +," blurb)
  1285.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1286.               (substring blurb (match-end 0)))))
  1287.     (while (string-match ", +" blurb)
  1288.       (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
  1289.               (substring blurb (match-end 0)))))
  1290.     (setq mode-line-process
  1291.       (format " %d/%d%s" rmail-current-message rmail-total-messages
  1292.           blurb))))
  1293.  
  1294. ;; Turn an attribute of a message on or off according to STATE.
  1295. ;; ATTR is the name of the attribute, as a string.
  1296. ;; MSGNUM is message number to change; nil means current message.
  1297. (defun rmail-set-attribute (attr state &optional msgnum)
  1298.   (let ((the-buf (current-buffer)))
  1299.     (if (eq major-mode 'mime/viewer-mode)
  1300.     (switch-to-buffer mime::preview/article-buffer)
  1301.       )
  1302.     (let ((omax (point-max-marker))
  1303.       (omin (point-min-marker))
  1304.       (buffer-read-only nil))
  1305.       (or msgnum (setq msgnum rmail-current-message))
  1306.       (if (> msgnum 0)
  1307.       (unwind-protect
  1308.           (save-excursion
  1309.         (widen)
  1310.         (goto-char (+ 3 (rmail-msgbeg msgnum)))
  1311.         (let ((curstate
  1312.                (not
  1313.             (null (search-backward (concat ", " attr ",")
  1314.                            (prog1 (point)
  1315.                          (end-of-line)) t)))))
  1316.           (or (eq curstate (not (not state)))
  1317.               (if curstate
  1318.               (delete-region (point) (1- (match-end 0)))
  1319.             (beginning-of-line)
  1320.             (forward-char 2)
  1321.             (insert " " attr ","))))
  1322.         (if (string= attr "deleted")
  1323.             (rmail-set-message-deleted-p msgnum state)))
  1324.         ;; Note: we don't use save-restriction
  1325.         ;;    because that does not work right
  1326.         ;; if changes are made outside the saved restriction
  1327.         ;; before that restriction is restored.
  1328.         (narrow-to-region omin omax)
  1329.         (set-marker omin nil)
  1330.         (set-marker omax nil)
  1331.         (if (= msgnum rmail-current-message)
  1332.         (rmail-display-labels)))))
  1333.     (switch-to-buffer the-buf)
  1334.     ))
  1335.  
  1336. ;; Return t if the attributes/keywords line of msg number MSG
  1337. ;; contains a match for the regexp LABELS.
  1338. (defun rmail-message-labels-p (msg labels)
  1339.   (save-excursion
  1340.     (save-restriction
  1341.       (widen)
  1342.       (goto-char (rmail-msgbeg msg))
  1343.       (forward-char 3)
  1344.       (re-search-backward labels (prog1 (point) (end-of-line)) t))))
  1345.  
  1346. ;;;; *** Rmail Message Selection And Support ***
  1347.  
  1348. (defun rmail-msgend (n)
  1349.   (marker-position (aref rmail-message-vector (1+ n))))
  1350.  
  1351. (defun rmail-msgbeg (n)
  1352.   (marker-position (aref rmail-message-vector n)))
  1353.  
  1354. (defun rmail-widen-to-current-msgbeg (function)
  1355.   "Call FUNCTION with point at start of internal data of current message.
  1356. Assumes that bounds were previously narrowed to display the message in Rmail.
  1357. The bounds are widened enough to move point where desired, then narrowed
  1358. again afterward.
  1359.  
  1360. FUNCTION may not change the visible text of the message, but it may
  1361. change the invisible header text."
  1362.   (save-excursion
  1363.     (let ((obeg (- (point-max) (point-min))))
  1364.       (unwind-protect
  1365.       (progn
  1366.         (narrow-to-region (rmail-msgbeg rmail-current-message)
  1367.                   (point-max))
  1368.         (goto-char (point-min))
  1369.         (funcall function))
  1370.     ;; Note: we don't use save-restriction because that does not work right
  1371.     ;; if changes are made outside the saved restriction
  1372.     ;; before that restriction is restored.
  1373.     ;; Here we assume that changes made by FUNCTION
  1374.     ;; occur before the visible region of the message.
  1375.     (narrow-to-region (- (point-max) obeg) (point-max))))))
  1376.  
  1377. (defun rmail-forget-messages ()
  1378.   (unwind-protect
  1379.       (if (vectorp rmail-message-vector)
  1380.       (let* ((i 0)
  1381.          (v rmail-message-vector)
  1382.          (n (length v)))
  1383.         (while (< i n)
  1384.           (move-marker (aref v i)  nil)
  1385.           (setq i (1+ i)))))
  1386.     (setq rmail-message-vector nil)
  1387.     (setq rmail-deleted-vector nil)))
  1388.  
  1389. (defun rmail-maybe-set-message-counters ()
  1390.   (if (not (and rmail-deleted-vector
  1391.         rmail-message-vector
  1392.         rmail-current-message
  1393.         rmail-total-messages))
  1394.       (rmail-set-message-counters)))
  1395.  
  1396. (defun rmail-count-new-messages (&optional nomsg)
  1397.   (let* ((case-fold-search nil)
  1398.      (total-messages 0)
  1399.      (messages-head nil)
  1400.      (deleted-head nil))
  1401.     (or nomsg (message "Counting new messages..."))
  1402.     (goto-char (point-max))
  1403.     ;; Put at the end of messages-head
  1404.     ;; the entry for message N+1, which marks
  1405.     ;; the end of message N.  (N = number of messages).
  1406.     (search-backward "\n\^_")
  1407.     (forward-char 1)
  1408.     (setq messages-head (list (point-marker)))
  1409.     (rmail-set-message-counters-counter (point-min))
  1410.     (setq rmail-current-message (1+ rmail-total-messages))
  1411.     (setq rmail-total-messages
  1412.       (+ rmail-total-messages total-messages))
  1413.     (setq rmail-message-vector
  1414.       (vconcat rmail-message-vector (cdr messages-head)))
  1415.     (aset rmail-message-vector
  1416.       rmail-current-message (car messages-head))
  1417.     (setq rmail-deleted-vector
  1418.       (concat rmail-deleted-vector deleted-head))
  1419.     (setq rmail-summary-vector
  1420.       (vconcat rmail-summary-vector (make-vector total-messages nil)))
  1421.     (goto-char (point-min))
  1422.     (or nomsg (message "Counting new messages...done (%d)" total-messages))))
  1423.  
  1424. (defun rmail-set-message-counters ()
  1425.   (rmail-forget-messages)
  1426.   (save-excursion
  1427.     (save-restriction
  1428.       (widen)
  1429.       (let* ((point-save (point))
  1430.          (total-messages 0)
  1431.          (messages-after-point)
  1432.          (case-fold-search nil)
  1433.          (messages-head nil)
  1434.          (deleted-head nil))
  1435.     (message "Counting messages...")
  1436.     (goto-char (point-max))
  1437.     ;; Put at the end of messages-head
  1438.     ;; the entry for message N+1, which marks
  1439.     ;; the end of message N.  (N = number of messages).
  1440.     (search-backward "\n\^_")
  1441.     (forward-char 1)
  1442.     (setq messages-head (list (point-marker)))
  1443.     (rmail-set-message-counters-counter (min (point) point-save))
  1444.     (setq messages-after-point total-messages)
  1445.     (rmail-set-message-counters-counter)
  1446.     (setq rmail-total-messages total-messages)
  1447.     (setq rmail-current-message
  1448.           (min total-messages
  1449.            (max 1 (- total-messages messages-after-point))))
  1450.     (setq rmail-message-vector
  1451.           (apply 'vector (cons (point-min-marker) messages-head))
  1452.           rmail-deleted-vector (concat "D" deleted-head)
  1453.           rmail-summary-vector (make-vector rmail-total-messages nil))
  1454.     (message "Counting messages...done")))))
  1455.     
  1456. (defun rmail-set-message-counters-counter (&optional stop)
  1457.   (while (search-backward "\n\^_\^L\n" stop t)
  1458.     (forward-char 1)
  1459.     (setq messages-head (cons (point-marker) messages-head))
  1460.     (save-excursion
  1461.       (setq deleted-head
  1462.         (cons (if (search-backward ", deleted,"
  1463.                        (prog1 (point)
  1464.                      (forward-line 2))
  1465.                        t)
  1466.               ?D ?\ )
  1467.           deleted-head)))
  1468.     (if (zerop (% (setq total-messages (1+ total-messages)) 20))
  1469.     (message "Counting messages...%d" total-messages))))
  1470.  
  1471. (defun rmail-beginning-of-message ()
  1472.   "Show current message starting from the beginning."
  1473.   (interactive)
  1474.   (rmail-show-message rmail-current-message))
  1475.  
  1476. (defun rmail-show-message (&optional n)
  1477.   "Show message number N (prefix argument), counting from start of file.
  1478. If summary buffer is currently displayed, update current message there also."
  1479.   (interactive "p")
  1480.   (if (eq major-mode 'mime/viewer-mode)
  1481.       (switch-to-buffer mime::preview/article-buffer)
  1482.     )
  1483.   (rmail-maybe-set-message-counters)
  1484.   (widen)
  1485.   (if (zerop rmail-total-messages)
  1486.       (progn (narrow-to-region (point-min) (1- (point-max)))
  1487.          (goto-char (point-min))
  1488.          (setq mode-line-process nil))
  1489.     (let (blurb)
  1490.       (if (not n)
  1491.       (setq n rmail-current-message)
  1492.     (cond ((<= n 0)
  1493.            (setq n 1
  1494.              rmail-current-message 1
  1495.              blurb "No previous message"))
  1496.           ((> n rmail-total-messages)
  1497.            (setq n rmail-total-messages
  1498.              rmail-current-message rmail-total-messages
  1499.              blurb "No following message"))
  1500.           (t
  1501.            (setq rmail-current-message n))))
  1502.       (let ((beg (rmail-msgbeg n))
  1503.         (end (rmail-msgend n)))
  1504.     (goto-char beg)
  1505.     (forward-line 1)
  1506.     (if (= (following-char) ?0)
  1507.         (progn
  1508.           (rmail-reformat-message beg end)
  1509.           (rmail-set-attribute "unseen" nil))
  1510.       (search-forward "\n*** EOOH ***\n" end t)
  1511.       (narrow-to-region (point) end))
  1512.     (goto-char (point-min))
  1513.     (rmail-display-labels)
  1514.     (if rmail-show-mime
  1515.         (funcall rmail-show-mime-method)
  1516.       )
  1517.     (run-hooks 'rmail-show-message-hook)
  1518.     ;; If there is a summary buffer, try to move to this message
  1519.     ;; in that buffer.  But don't complain if this message
  1520.     ;; is not mentioned in the summary.
  1521.     (if (rmail-summary-exists)
  1522.         (let ((curr-msg rmail-current-message))
  1523.           (rmail-select-summary
  1524.            (rmail-summary-goto-msg curr-msg t t))))
  1525.     (if blurb
  1526.         (message blurb))))))
  1527.  
  1528. (defun rmail-next-message (n)
  1529.   "Show following message whether deleted or not.
  1530. With prefix arg N, moves forward N messages, or backward if N is negative."
  1531.   (interactive "p")
  1532.   (if (eq major-mode 'mime/viewer-mode)
  1533.       (switch-to-buffer mime::preview/article-buffer)
  1534.     )
  1535.   (rmail-maybe-set-message-counters)
  1536.   (rmail-show-message (+ rmail-current-message n)))
  1537.  
  1538. (defun rmail-previous-message (n)
  1539.   "Show previous message whether deleted or not.
  1540. With prefix arg N, moves backward N messages, or forward if N is negative."
  1541.   (interactive "p")
  1542.   (rmail-next-message (- n)))
  1543.  
  1544. (defun rmail-next-undeleted-message (n)
  1545.   "Show following non-deleted message.
  1546. With prefix arg N, moves forward N non-deleted messages,
  1547. or backward if N is negative.
  1548.  
  1549. Returns t if a new message is being shown, nil otherwise."
  1550.   (interactive "p")
  1551.   (let ((the-buf (current-buffer)))
  1552.     (if (eq major-mode 'mime/viewer-mode)
  1553.     (switch-to-buffer mime::preview/article-buffer)
  1554.       )
  1555.     (rmail-maybe-set-message-counters)
  1556.     (let ((lastwin rmail-current-message)
  1557.       (current rmail-current-message))
  1558.       (while (and (> n 0) (< current rmail-total-messages))
  1559.     (setq current (1+ current))
  1560.     (if (not (rmail-message-deleted-p current))
  1561.         (setq lastwin current n (1- n))))
  1562.       (while (and (< n 0) (> current 1))
  1563.     (setq current (1- current))
  1564.     (if (not (rmail-message-deleted-p current))
  1565.         (setq lastwin current n (1+ n))))
  1566.       (if (/= lastwin rmail-current-message)
  1567.       (progn (rmail-show-message lastwin)
  1568.          t)
  1569.     (if (< n 0)
  1570.         (message "No previous nondeleted message"))
  1571.     (if (> n 0)
  1572.         (message "No following nondeleted message"))
  1573.     (switch-to-buffer the-buf)
  1574.     nil))))
  1575.  
  1576. (defun rmail-previous-undeleted-message (n)
  1577.   "Show previous non-deleted message.
  1578. With prefix argument N, moves backward N non-deleted messages,
  1579. or forward if N is negative."
  1580.   (interactive "p")
  1581.   (rmail-next-undeleted-message (- n)))
  1582.  
  1583. (defun rmail-first-message ()
  1584.   "Show first message in file."
  1585.   (interactive)
  1586.   (rmail-maybe-set-message-counters)
  1587.   (rmail-show-message 1))
  1588.  
  1589. (defun rmail-last-message ()
  1590.   "Show last message in file."
  1591.   (interactive)
  1592.   (rmail-maybe-set-message-counters)
  1593.   (rmail-show-message rmail-total-messages))
  1594.  
  1595. (defun rmail-what-message ()
  1596.   (let ((where (point))
  1597.     (low 1)
  1598.     (high rmail-total-messages)
  1599.     (mid (/ rmail-total-messages 2)))
  1600.     (while (> (- high low) 1)
  1601.       (if (>= where (rmail-msgbeg mid))
  1602.       (setq low mid)
  1603.     (setq high mid))
  1604.       (setq mid (+ low (/ (- high low) 2))))
  1605.     (if (>= where (rmail-msgbeg high)) high low)))
  1606.  
  1607. (defun rmail-message-recipients-p (msg recipients &optional primary-only)
  1608.   (save-restriction
  1609.     (goto-char (rmail-msgbeg msg))
  1610.     (search-forward "\n*** EOOH ***\n")
  1611.     (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
  1612.     (or (string-match recipients (or (mail-fetch-field "To") ""))
  1613.     (string-match recipients (or (mail-fetch-field "From") ""))
  1614.     (if (not primary-only)
  1615.         (string-match recipients (or (mail-fetch-field "Cc") ""))))))
  1616.  
  1617. (defun rmail-message-regexp-p (msg regexp)
  1618.   "Return t, if for message number MSG, regexp REGEXP matches in the header."
  1619.   (goto-char (rmail-msgbeg msg))
  1620.   (let ((end 
  1621.          (save-excursion 
  1622.            (search-forward "*** EOOH ***" (point-max)) (point))))
  1623.     (re-search-forward regexp end t)))
  1624.  
  1625. (defvar rmail-search-last-regexp nil) ; jwz: moved this up
  1626. (defun rmail-search-backward (regexp &optional n)
  1627.   "Show message containing next match for REGEXP.
  1628. Prefix argument gives repeat count; negative argument means search
  1629. backwards (through earlier messages).
  1630. Interactively, empty argument means use same regexp used last time."
  1631.   (interactive
  1632.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1633.        (prompt
  1634.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1635.        regexp)
  1636.       (if rmail-search-last-regexp
  1637.       (setq prompt (concat prompt
  1638.                    "(default "
  1639.                    rmail-search-last-regexp
  1640.                    ") ")))
  1641.       (setq regexp (read-string prompt))
  1642.       (cond ((not (equal regexp ""))
  1643.          (setq rmail-search-last-regexp regexp))
  1644.         ((not rmail-search-last-regexp)
  1645.          (error "No previous Rmail search string")))
  1646.       (list rmail-search-last-regexp
  1647.         (prefix-numeric-value current-prefix-arg))))
  1648.   (rmail-search regexp (- n)))
  1649.  
  1650. (defun rmail-search (regexp &optional n)
  1651.   "Show message containing next match for REGEXP.
  1652. Prefix argument gives repeat count; negative argument means search
  1653. backwards (through earlier messages).
  1654. Interactively, empty argument means use same regexp used last time."
  1655.   (interactive
  1656.     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
  1657.        (prompt
  1658.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1659.        regexp)
  1660.       (if rmail-search-last-regexp
  1661.       (setq prompt (concat prompt
  1662.                    "(default "
  1663.                    rmail-search-last-regexp
  1664.                    ") ")))
  1665.       (setq regexp (read-string prompt))
  1666.       (cond ((not (equal regexp ""))
  1667.          (setq rmail-search-last-regexp regexp))
  1668.         ((not rmail-search-last-regexp)
  1669.          (error "No previous Rmail search string")))
  1670.       (list rmail-search-last-regexp
  1671.         (prefix-numeric-value current-prefix-arg))))
  1672.   (or n (setq n 1))
  1673.   (message "%sRmail search for %s..."
  1674.        (if (< n 0) "Reverse " "")
  1675.        regexp)
  1676.   (rmail-maybe-set-message-counters)
  1677.   (let ((omin (point-min))
  1678.     (omax (point-max))
  1679.     (opoint (point))
  1680.     win
  1681.     (reversep (< n 0))
  1682.     (msg rmail-current-message))
  1683.     (unwind-protect
  1684.     (progn
  1685.       (widen)
  1686.       (while (/= n 0)
  1687.         ;; Check messages one by one, advancing message number up or down
  1688.         ;; but searching forward through each message.
  1689.         (if reversep
  1690.         (while (and (null win) (> msg 1))
  1691.           (goto-char (rmail-msgbeg (setq msg (1- msg))))
  1692.           (setq win (re-search-forward
  1693.                  regexp (rmail-msgend msg) t)))
  1694.           (while (and (null win) (< msg rmail-total-messages))
  1695.         (goto-char (rmail-msgbeg (setq msg (1+ msg))))
  1696.         (setq win (re-search-forward regexp (rmail-msgend msg) t))))
  1697.         (setq n (+ n (if reversep 1 -1)))))
  1698.       (if win
  1699.       (progn
  1700.         ;; If this is a reverse search and we found a message,
  1701.         ;; search backward thru this message to position point.
  1702.         (if reversep
  1703.         (progn
  1704.           (goto-char (rmail-msgend msg))
  1705.           (re-search-backward
  1706.            regexp (rmail-msgbeg msg) t)))
  1707.         (setq win (point))
  1708.         (rmail-show-message msg)
  1709.         (message "%sRmail search for %s...done"
  1710.              (if reversep "Reverse " "")
  1711.              regexp)
  1712.         (goto-char win))
  1713.     (goto-char opoint)
  1714.     (narrow-to-region omin omax)
  1715.     (ding)
  1716.     (message "Search failed: %s" regexp)))))
  1717.  
  1718. (defun rmail-search-backwards (regexp &optional n)
  1719.   "Show message containing previous match for REGEXP.
  1720. Prefix argument gives repeat count; negative argument means search
  1721. forward (through later messages).
  1722. Interactively, empty argument means use same regexp used last time."
  1723.   (interactive
  1724.     (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
  1725.        (prompt
  1726.         (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
  1727.        regexp)
  1728.       (if rmail-search-last-regexp
  1729.       (setq prompt (concat prompt
  1730.                    "(default "
  1731.                    rmail-search-last-regexp
  1732.                    ") ")))
  1733.       (setq regexp (read-string prompt))
  1734.       (cond ((not (equal regexp ""))
  1735.          (setq rmail-search-last-regexp regexp))
  1736.         ((not rmail-search-last-regexp)
  1737.          (error "No previous Rmail search string")))
  1738.       (list rmail-search-last-regexp
  1739.         (prefix-numeric-value current-prefix-arg))))
  1740.   (rmail-search regexp (- (or n -1))))
  1741.  
  1742. ;; Show the first message which has the `unseen' attribute.
  1743. (defun rmail-first-unseen-message ()
  1744.   (rmail-maybe-set-message-counters)
  1745.   (let ((current 1)
  1746.     found)
  1747.     (save-restriction
  1748.       (widen)
  1749.       (while (and (not found) (< current rmail-total-messages))
  1750.     (if (rmail-message-labels-p current ", ?\\(unseen\\),")
  1751.         (setq found current))
  1752.     (setq current (1+ current))))
  1753. ;; Let the caller show the message.
  1754. ;;    (if found
  1755. ;;    (rmail-show-message found))
  1756.     found))
  1757.  
  1758. ;;;; *** Rmail Message Deletion Commands ***
  1759.  
  1760. (defun rmail-message-deleted-p (n)
  1761.   (= (aref rmail-deleted-vector n) ?D))
  1762.  
  1763. (defun rmail-set-message-deleted-p (n state)
  1764.   (aset rmail-deleted-vector n (if state ?D ?\ )))
  1765.  
  1766. (defun rmail-delete-message ()
  1767.   "Delete this message and stay on it."
  1768.   (interactive)
  1769.   (rmail-set-attribute "deleted" t))
  1770.  
  1771. (defun rmail-undelete-previous-message ()
  1772.   "Back up to deleted message, select it, and undelete it."
  1773.   (interactive)
  1774.   (let ((msg rmail-current-message))
  1775.     (while (and (> msg 0)
  1776.         (not (rmail-message-deleted-p msg)))
  1777.       (setq msg (1- msg)))
  1778.     (if (= msg 0)
  1779.     (error "No previous deleted message")
  1780.       (if (/= msg rmail-current-message)
  1781.       (rmail-show-message msg))
  1782.       (rmail-set-attribute "deleted" nil)
  1783.       (if (rmail-summary-exists)
  1784.       (save-excursion
  1785.         (set-buffer rmail-summary-buffer)
  1786.         (rmail-summary-mark-undeleted msg)))
  1787.       (rmail-maybe-display-summary))))
  1788.  
  1789. (defun rmail-delete-forward (&optional backward)
  1790.   "Delete this message and move to next nondeleted one.
  1791. Deleted messages stay in the file until the \\[rmail-expunge] command is given.
  1792. With prefix argument, delete and move backward.
  1793.  
  1794. Returns t if a new message is displayed after the delete, or nil otherwise."
  1795.   (interactive "P")
  1796.   (rmail-set-attribute "deleted" t)
  1797.   (let ((del-msg rmail-current-message))
  1798.     (if (rmail-summary-exists)
  1799.     (save-excursion
  1800.       (set-buffer rmail-summary-buffer)
  1801.       (rmail-summary-mark-deleted del-msg)))
  1802.     (prog1 (rmail-next-undeleted-message (if backward -1 1))
  1803.       (rmail-maybe-display-summary))))
  1804.  
  1805. (defun rmail-delete-backward ()
  1806.   "Delete this message and move to previous nondeleted one.
  1807. Deleted messages stay in the file until the \\[rmail-expunge] command is given."
  1808.   (interactive)
  1809.   (rmail-delete-forward t))
  1810.  
  1811. (defun rmail-only-expunge ()
  1812.   "Actually erase all deleted messages in the file."
  1813.   (interactive)
  1814.   (message "Expunging deleted messages...")
  1815.   ;; Discard all undo records for this buffer.
  1816.   (or (eq buffer-undo-list t)
  1817.       (setq buffer-undo-list nil))
  1818.   (rmail-maybe-set-message-counters)
  1819.   (let* ((omax (- (buffer-size) (point-max)))
  1820.      (omin (- (buffer-size) (point-min)))
  1821.      (opoint (if (and (> rmail-current-message 0)
  1822.               (= ?D (aref rmail-deleted-vector rmail-current-message)))
  1823.              0 (- (point) (point-min))))
  1824.      (messages-head (cons (aref rmail-message-vector 0) nil))
  1825.      (messages-tail messages-head)
  1826.      ;; Don't make any undo records for the expunging.
  1827.      (buffer-undo-list t)
  1828.      (win))
  1829.     (unwind-protect
  1830.     (save-excursion
  1831.       (widen)
  1832.       (goto-char (point-min))
  1833.       (let ((counter 0)
  1834.         (number 1)
  1835.         (total rmail-total-messages)
  1836.         (new-message-number rmail-current-message)
  1837.         (new-summary nil)
  1838.         (buffer-read-only nil)
  1839.         (messages rmail-message-vector)
  1840.         (deleted rmail-deleted-vector)
  1841.         (summary rmail-summary-vector))
  1842.         (setq rmail-total-messages nil
  1843.           rmail-current-message nil
  1844.           rmail-message-vector nil
  1845.           rmail-deleted-vector nil
  1846.           rmail-summary-vector nil)
  1847.         (while (<= number total)
  1848.           (if (= (aref deleted number) ?D)
  1849.           (progn
  1850.             (delete-region
  1851.               (marker-position (aref messages number))
  1852.               (marker-position (aref messages (1+ number))))
  1853.             (move-marker (aref messages number) nil)
  1854.             (if (> new-message-number counter)
  1855.             (setq new-message-number (1- new-message-number))))
  1856.         (setq counter (1+ counter))
  1857.         (setq messages-tail
  1858.               (setcdr messages-tail
  1859.                   (cons (aref messages number) nil)))
  1860.         (setq new-summary
  1861.               (cons (if (= counter number) (aref summary (1- number)))
  1862.                 new-summary)))
  1863.           (if (zerop (% (setq number (1+ number)) 20))
  1864.           (message "Expunging deleted messages...%d" number)))
  1865.         (setq messages-tail
  1866.           (setcdr messages-tail
  1867.               (cons (aref messages number) nil)))
  1868.         (setq rmail-current-message new-message-number
  1869.           rmail-total-messages counter
  1870.           rmail-message-vector (apply 'vector messages-head)
  1871.           rmail-deleted-vector (make-string (1+ counter) ?\ )
  1872.           rmail-summary-vector (vconcat (nreverse new-summary))
  1873.           win t)))
  1874.       (message "Expunging deleted messages...done")
  1875.       (if (not win)
  1876.       (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
  1877.       (rmail-show-message
  1878.        (if (zerop rmail-current-message) 1 nil))
  1879.       ;; 1996/12/9 by MORIOKA Tomohiko <morioka@jaist.ac.jp>
  1880.       ;;    to avoid error but it is quit bad way
  1881.       (if (> (+ (point) opoint)(point-max))
  1882.       (goto-char (point-max))
  1883.     (forward-char opoint)
  1884.     ))))
  1885.  
  1886. (defun rmail-expunge ()
  1887.   "Erase deleted messages from Rmail file and summary buffer."
  1888.   (interactive)
  1889.   (rmail-only-expunge)
  1890.   (if (rmail-summary-exists)
  1891.       (rmail-select-summary
  1892.     (rmail-update-summary))))
  1893.  
  1894. ;;;; *** Rmail Mailing Commands ***
  1895.  
  1896. (defun rmail-start-mail (&rest args)
  1897.   (if (and window-system rmail-mail-new-frame)
  1898.       (prog1
  1899.     (apply 'mail-other-frame args)
  1900.     (modify-frame-parameters (selected-frame)
  1901.                  '((dedicated . t))))
  1902.     (apply 'mail-other-window args)))
  1903.  
  1904. (defun rmail-mail ()
  1905.   "Send mail in another window.
  1906. While composing the message, use \\[mail-yank-original] to yank the
  1907. original message into it."
  1908.   (interactive)
  1909.   (rmail-start-mail nil nil nil nil nil (current-buffer)))
  1910.  
  1911. (defun rmail-continue ()
  1912.   "Continue composing outgoing message previously being composed."
  1913.   (interactive)
  1914.   (rmail-start-mail t))
  1915.  
  1916. (defun rmail-reply (just-sender)
  1917.   "Reply to the current message.
  1918. Normally include CC: to all other recipients of original message;
  1919. prefix argument means ignore them.  While composing the reply,
  1920. use \\[mail-yank-original] to yank the original message into it."
  1921.   (interactive "P")
  1922.   (let (from reply-to cc subject date to message-id resent-reply-to)
  1923.     (save-excursion
  1924.       (save-restriction
  1925.     (widen)
  1926.     (goto-char (rmail-msgbeg rmail-current-message))
  1927.     (forward-line 1)
  1928.     (if (= (following-char) ?0)
  1929.         (narrow-to-region
  1930.          (progn (forward-line 2)
  1931.             (point))
  1932.          (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
  1933.                     'move)
  1934.             (point)))
  1935.       (narrow-to-region (point)
  1936.                 (progn (search-forward "\n*** EOOH ***\n")
  1937.                    (beginning-of-line) (point))))
  1938.     (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
  1939.           from (mail-fetch-field "from")
  1940.           reply-to (or resent-reply-to
  1941.                (mail-fetch-field "reply-to" nil t)
  1942.                from)
  1943.           cc (cond (just-sender nil)
  1944.                (resent-reply-to (mail-fetch-field "resent-cc" t))
  1945.                (t (mail-fetch-field "cc" nil t)))
  1946.           subject (or (and resent-reply-to
  1947.                    (mail-fetch-field "resent-subject" t))
  1948.               (mail-fetch-field "subject"))
  1949.           date (cond (resent-reply-to
  1950.               (mail-fetch-field "resent-date" t))
  1951.              ((mail-fetch-field "date")))
  1952.           to (cond (resent-reply-to
  1953.             (mail-fetch-field "resent-to" t))
  1954.                ((mail-fetch-field "to" nil t))
  1955.                ;((mail-fetch-field "apparently-to")) ack gag barf
  1956.                (t ""))
  1957.           message-id (cond (resent-reply-to
  1958.                 (mail-fetch-field "resent-message-id" t))
  1959.                    ((mail-fetch-field "message-id"))))))
  1960.     (and (stringp subject)
  1961.      (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
  1962.                subject)
  1963.          (setq subject (concat rmail-reply-prefix subject))))
  1964.     (rmail-start-mail nil
  1965.       (mail-strip-quoted-names reply-to)
  1966.       subject
  1967.       (rmail-make-in-reply-to-field from date message-id)
  1968.       (if just-sender
  1969.       nil
  1970.     (let* ((cc-list (rmail-dont-reply-to
  1971.               (mail-strip-quoted-names
  1972.                 (if (null cc) to (concat to ", " cc))))))
  1973.       (if (string= cc-list "") nil cc-list)))
  1974.       (current-buffer)
  1975.       (list (list '(lambda (buf msgnum)
  1976.              (save-excursion
  1977.                (set-buffer buf)
  1978.                (rmail-set-attribute "answered" t msgnum)))
  1979.           (current-buffer) rmail-current-message)))))
  1980.  
  1981. (defun rmail-make-in-reply-to-field (from date message-id)
  1982.   (cond ((not from)
  1983.          (if message-id
  1984.              message-id
  1985.              nil))
  1986.         (mail-use-rfc822
  1987.          (require 'rfc822)
  1988.          (let ((tem (car (rfc822-addresses from))))
  1989.            (if message-id
  1990.                (if (string-match
  1991.                     (regexp-quote (if (string-match "@[^@]*\\'" tem)
  1992.                                       (substring tem 0 (match-beginning 0))
  1993.                                       tem))
  1994.                     message-id)
  1995.                    ;; Message-ID is sufficiently informative
  1996.                    message-id
  1997.                    (concat message-id " (" tem ")"))
  1998.                ;; Use prin1 to fake RFC822 quoting
  1999.                (let ((field (prin1-to-string tem)))
  2000.                  (if date
  2001.                      (concat field "'s message of " date)
  2002.                      field)))))
  2003.         ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
  2004.                 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
  2005.            ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
  2006.            (or (string-match (concat "\\`[ \t]*\\(" bar
  2007.                                      "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
  2008.                              ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
  2009.                              from)
  2010.                (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
  2011.                                      bar "\\))[ \t]*\\'")
  2012.                              ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
  2013.                              from)))
  2014.          (let ((start (match-beginning 1))
  2015.                (end (match-end 1)))
  2016.            ;; Trim whitespace which above regexp match allows
  2017.            (while (and (< start end)
  2018.                        (memq (aref from start) '(?\t ?\ )))
  2019.              (setq start (1+ start)))
  2020.            (while (and (< start end)
  2021.                        (memq (aref from (1- end)) '(?\t ?\ )))
  2022.              (setq end (1- end)))
  2023.            (let ((field (substring from start end)))
  2024.              (if date (setq field (concat "message from " field " on " date)))
  2025.              (if message-id
  2026.                  ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
  2027.                  (concat message-id " (" field ")")
  2028.                  field))))
  2029.         (t
  2030.          ;; If we can't kludge it simply, do it correctly
  2031.          (let ((mail-use-rfc822 t))
  2032.            (rmail-make-in-reply-to-field from date message-id)))))
  2033.  
  2034. (defun rmail-forward (resend)
  2035.   "Forward the current message to another user.
  2036. With prefix argument, \"resend\" the message instead of forwarding it;
  2037. see the documentation of `rmail-resend'."
  2038.   (interactive "P")
  2039.   (if resend
  2040.       (call-interactively 'rmail-resend)
  2041.     (let ((forward-buffer (current-buffer))
  2042.       (subject (concat "["
  2043.                (let ((from (or (mail-fetch-field "From")
  2044.                        (mail-fetch-field ">From"))))
  2045.                  (if from
  2046.                  (concat (mail-strip-quoted-names from) ": ")
  2047.                    ""))
  2048.                (or (mail-fetch-field "Subject") "")
  2049.                "]")))
  2050.       ;; If only one window, use it for the mail buffer.
  2051.       ;; Otherwise, use another window for the mail buffer
  2052.       ;; so that the Rmail buffer remains visible
  2053.       ;; and sending the mail will get back to it.
  2054.       (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
  2055.                (function mail)
  2056.              (function rmail-start-mail))
  2057.            nil nil subject nil nil nil
  2058.            (list (list (function (lambda (buf msgnum)
  2059.                        (save-excursion
  2060.                          (set-buffer buf)
  2061.                          (rmail-set-attribute
  2062.                           "forwarded" t msgnum))))
  2063.                    (current-buffer)
  2064.                    rmail-current-message)))
  2065.       (save-excursion
  2066.         ;; Insert after header separator--before signature if any.
  2067.         (goto-char (point-min))
  2068.         (search-forward-regexp
  2069.          (concat "^" (regexp-quote mail-header-separator)))
  2070.         (forward-line 1)
  2071.         (insert-buffer forward-buffer))))))
  2072.  
  2073. (defun rmail-resend (address &optional from comment mail-alias-file)
  2074.   "Resend current message to ADDRESSES.
  2075. ADDRESSES should be a single address, a a string consisting of several
  2076. addresses separated by commas, or a list of addresses.
  2077.  
  2078. Optional FROM is the address to resend the message from, and
  2079. defaults to the username of the person redistributing the message.
  2080. Optional COMMENT is a string that will be inserted as a comment in the
  2081. resent message.
  2082. Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
  2083. typically for purposes of moderating a list."
  2084.   (interactive "sResend to: ")
  2085.   (require 'sendmail)
  2086.   ;;(require 'mailalias)
  2087.   (if (not from) (setq from (user-login-name)))
  2088.   (let ((tembuf (generate-new-buffer " sendmail temp"))
  2089.     (mail-header-separator "")
  2090.     (case-fold-search nil)
  2091.     (mailbuf (current-buffer)))
  2092.     (unwind-protect
  2093.     (save-excursion
  2094.       ;;>> Copy message into temp buffer
  2095.       (set-buffer tembuf)
  2096.       (insert-buffer-substring mailbuf)
  2097.       (goto-char (point-min))
  2098.       ;; Delete any Sender field, since that's not specifyable.
  2099.       (if (re-search-forward "^Sender:" nil t)
  2100.           (let (beg)
  2101.         (beginning-of-line)
  2102.         (setq beg (point))
  2103.         (forward-line 1)
  2104.         (while (looking-at "[ \t]")
  2105.           (forward-line 1))
  2106.         (delete-region beg (point))))
  2107.       ;;>> Insert resent-from:
  2108.       (insert "Resent-From: " from "\n")
  2109.       (insert "Resent-Date: " (mail-rfc822-date) "\n")
  2110.       ;;>> Insert resent-to: and bcc if need be.
  2111.       (progn ;;let ((before (point)))
  2112.         (if mail-self-blind
  2113.         (insert "Resent-Bcc: " (user-login-name) "\n"))
  2114.         (insert "Resent-To: " (if (stringp address)
  2115.                    address
  2116.                  (mapconcat 'identity address ",\n\t"))
  2117.             "\n")
  2118.         ;; lose this loser. -jwz
  2119.         ;;(expand-mail-aliases before (point))
  2120.         )
  2121.       ;;>> Set up comment, if any.
  2122.       (if (and (sequencep comment) (not (zerop (length comment))))
  2123.           (let ((before (point))
  2124.             after)
  2125.         (insert comment)
  2126.         (or (eolp) (insert "\n"))
  2127.         (setq after (point))
  2128.         (goto-char before)
  2129.         (while (< (point) after)
  2130.           (insert "Resent-Comment: ")
  2131.           (forward-line 1))))
  2132.       ;; Don't expand aliases in the destination fields
  2133.       ;; of the original message.
  2134.       (let (mail-aliases)
  2135.         (sendmail-send-it)))
  2136.       (kill-buffer tembuf))
  2137.     (rmail-set-attribute "resent" t rmail-current-message)))
  2138.  
  2139. (defvar mail-unsent-separator
  2140.   (concat "^ *---+ +Unsent message follows +---+ *$\\|"
  2141.       "^ *---+ +Returned message +---+ *$\\|"
  2142.       "^ *---+ +Original message +---+ *$\\|"
  2143.       "^ *--+ +begin message +--+ *$\\|"
  2144.       "^ *---+ +Original message follows +---+ *$\\|"
  2145.       "^|? *---+ +Message text follows: +---+ *|?$"))
  2146.  
  2147. (defun rmail-retry-failure ()
  2148.   "Edit a mail message which is based on the contents of the current message.
  2149. For a message rejected by the mail system, extract the interesting headers and
  2150. the body of the original message; otherwise copy the current message."
  2151.   (interactive)
  2152.   (require 'mail-utils)
  2153.   (let (to subj irp2 cc orig-message)
  2154.     (save-excursion
  2155.       ;; Narrow down to just the quoted original message
  2156.       (rmail-beginning-of-message)
  2157.       (let ((case-fold-search t))
  2158.     (or (re-search-forward mail-unsent-separator nil t)
  2159.         (error "Cannot parse this as a failure message")))
  2160.       (save-restriction
  2161.     (narrow-to-region (point) (point-max))
  2162.     ;; Now mail-fetch-field will get from headers of the original message,
  2163.     ;; not from the headers of the rejection.
  2164.     (setq to   (mail-fetch-field "To")
  2165.           subj (mail-fetch-field "Subject")
  2166.           irp2 (mail-fetch-field "In-reply-to")
  2167.           cc   (mail-fetch-field "Cc"))
  2168.     ;; Get the entire text (not headers) of the original message.
  2169.     (setq orig-message
  2170.           (buffer-substring
  2171.            (progn (search-forward "\n\n") (point))
  2172.            (point-max)))))
  2173.     ;; Start sending a new message; default header fields from the original.
  2174.     ;; Turn off the usual actions for initializing the message body
  2175.     ;; because we want to get only the text from the failure message.
  2176.     (let (mail-signature
  2177.       (mail-setup-hook rmail-retry-setup-hook))
  2178.       (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
  2179.       ;; Insert original text as initial text of new draft message.
  2180.       (progn
  2181.         (goto-char (point-max))
  2182.         (insert orig-message)
  2183.         (goto-char (point-min))
  2184.         (end-of-line))))))
  2185.  
  2186. (defun rmail-bury ()
  2187.   "Bury current Rmail buffer and its summary buffer."
  2188.   (interactive)
  2189.   (let ((rmail-buffer (current-buffer)))
  2190.     (if (rmail-summary-exists)
  2191.     (let (window)
  2192.       (while (setq window (get-buffer-window rmail-summary-buffer))
  2193.         (set-window-buffer window (other-buffer rmail-summary-buffer)))
  2194.       (bury-buffer rmail-summary-buffer)))
  2195.     (switch-to-buffer (other-buffer (current-buffer)))
  2196.     (bury-buffer rmail-buffer)))
  2197.  
  2198. (defun rmail-summary-exists ()
  2199.   "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
  2200. Non-nil value returned is the summary buffer."
  2201.   (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
  2202.        rmail-summary-buffer))
  2203.  
  2204. (defun rmail-summary-displayed ()
  2205.   "t iff in RMAIL buffer and an associated summary buffer is displayed."
  2206.   (and (rmail-summary-exists) (get-buffer-window rmail-summary-buffer)))
  2207.  
  2208. (defvar rmail-redisplay-summary nil
  2209.   "*Non-nil means Rmail should show the summary when it changes.
  2210. This has an effect only if a summary buffer exists.")
  2211.  
  2212. ;; Put the summary buffer back on the screen, if user wants that.
  2213. (defun rmail-maybe-display-summary ()
  2214.   (and (rmail-summary-exists)
  2215.        rmail-redisplay-summary
  2216.        (display-buffer rmail-summary-buffer)))
  2217.  
  2218. ;;;; *** Rmail Specify Inbox Files ***
  2219.  
  2220. (autoload 'set-rmail-inbox-list "rmailmsc"
  2221.   "Set the inbox list of the current RMAIL file to FILE-NAME.
  2222. This may be a list of file names separated by commas.
  2223. If FILE-NAME is empty, remove any inbox list."
  2224.   t)
  2225.  
  2226. ;;;; *** Rmail Commands for Labels ***
  2227.  
  2228. (autoload 'rmail-add-label "rmailkwd"
  2229.   "Add LABEL to labels associated with current RMAIL message.
  2230. Completion is performed over known labels when reading."
  2231.   t)
  2232.  
  2233. (autoload 'rmail-kill-label "rmailkwd"
  2234.   "Remove LABEL from labels associated with current RMAIL message.
  2235. Completion is performed over known labels when reading."
  2236.   t)
  2237.  
  2238. (autoload 'rmail-next-labeled-message "rmailkwd"
  2239.   "Show next message with LABEL.  Defaults to last label used.
  2240. With prefix argument N moves forward N messages with this label."
  2241.   t)
  2242.  
  2243. (autoload 'rmail-previous-labeled-message "rmailkwd"
  2244.   "Show previous message with LABEL.  Defaults to last label used.
  2245. With prefix argument N moves backward N messages with this label."
  2246.   t)
  2247.  
  2248. (autoload 'rmail-read-label "rmailkwd"
  2249.   "PROMPT and read with completion an Rmail message label."
  2250.   t)
  2251.  
  2252. ;;;; *** Rmail Edit Mode ***
  2253.  
  2254. (autoload 'rmail-edit-current-message "rmailedit"
  2255.   "Edit the contents of the current message"
  2256.   t)
  2257.  
  2258. ;;;; *** Rmail Sorting ***
  2259.  
  2260. (autoload 'rmail-sort-by-date "rmailsort"
  2261.   "Sort messages of current Rmail file by date.
  2262. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2263.  
  2264. (autoload 'rmail-sort-by-subject "rmailsort"
  2265.   "Sort messages of current Rmail file by subject.
  2266. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2267.  
  2268. (autoload 'rmail-sort-by-author "rmailsort"
  2269.   "Sort messages of current Rmail file by author.
  2270. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2271.  
  2272. (autoload 'rmail-sort-by-recipient "rmailsort"
  2273.   "Sort messages of current Rmail file by recipient.
  2274. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2275.  
  2276. (autoload 'rmail-sort-by-correspondent "rmailsort"
  2277.   "Sort messages of current Rmail file by other correspondent.
  2278. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2279.  
  2280. (autoload 'rmail-sort-by-lines "rmailsort"
  2281.   "Sort messages of current Rmail file by number of lines.
  2282. If prefix argument REVERSE is non-nil, sort them in reverse order." t)
  2283.  
  2284. ;;;; *** Rmail Summary Mode ***
  2285.  
  2286. (autoload 'rmail-summary "rmailsum"
  2287.   "Display a summary of all messages, one line per message."
  2288.   t)
  2289.  
  2290. (autoload 'rmail-summary-by-labels "rmailsum"
  2291.   "Display a summary of all messages with one or more LABELS.
  2292. LABELS should be a string containing the desired labels, separated by commas."
  2293.   t)
  2294.  
  2295. (autoload 'rmail-summary-by-recipients "rmailsum"
  2296.   "Display a summary of all messages with the given RECIPIENTS.
  2297. Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
  2298. is non-nil (prefix arg given), only look in the To and From fields.
  2299. RECIPIENTS is a string of regexps separated by commas."
  2300.   t)
  2301.  
  2302. (autoload 'rmail-summary-by-regexp "rmailsum"
  2303.   "Display a summary of all messages according to regexp REGEXP.
  2304. If the regular expression is found in the header of the message
  2305. \(including in the date and other lines, as well as the subject line),
  2306. Emacs will list the header line in the RMAIL-summary."
  2307.   t)
  2308.  
  2309. (autoload 'rmail-summary-by-topic "rmailsum"
  2310.   "Display a summary of all messages with the given SUBJECT.
  2311. Normally checks the Subject field of headers;
  2312. but if WHOLE-MESSAGE is non-nil (prefix arg given), 
  2313.  look in the whole message.
  2314. SUBJECT is a string of regexps separated by commas."
  2315.   t)
  2316.  
  2317. ;;;; *** Rmail output messages to files ***
  2318.  
  2319. (autoload 'rmail-output-to-rmail-file "rmailout"
  2320.   "Append the current message to an Rmail file named FILE-NAME.
  2321. If the file does not exist, ask if it should be created.
  2322. If file is being visited, the message is appended to the Emacs
  2323. buffer visiting that file."
  2324.   t)
  2325.  
  2326. (autoload 'rmail-output "rmailout"
  2327.   "Append this message to Unix mail file named FILE-NAME."
  2328.   t)
  2329.  
  2330. ;;;; *** Rmail undigestification ***
  2331.  
  2332. (autoload 'undigestify-rmail-message "undigest"
  2333.   "Break up a digest message into its constituent messages.
  2334. Leaves original message, deleted, before the undigestified messages."
  2335.   t)
  2336.  
  2337. (provide 'rmail)
  2338.  
  2339. ;;; rmail.el ends here
  2340.